Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3.2.5 - Multi Model Nested Form, Heroku NoMethodError
    text
    copied!<p>I have been searching high and low for answers and I'm at a standstill. Everything works on my local development environment but everythign blows up on production (Heroku). Using same database (postgres). Heroku blows up a NoMethodError even though I don't believe I'm ever sending to that method.</p> <p>I have main 3 models (additional join model), one nested form that has a has_many :through submitting to all three models, and Static_Pages#signup (acting as new action) and a Subscriptions_Controller#create where the issue is happening.</p> <p><strong>Models</strong></p> <pre><code>class Location &lt; ActiveRecord::Base attr_accessible :address_line_2, :city, :lat, :long, :name, :state, :street_address, :website, :zip, :phone_number, :user_id has_many :relationships has_many :users, :through =&gt; :relationships end class User &lt; ActiveRecord::Base has_one :subscription has_one :plan, :through =&gt; :subscription has_many :relationships has_many :locations, :through =&gt; :relationships devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :remember_me, :stripe_token, :phone_number,:location end class Subscription &lt; ActiveRecord::Base attr_accessor :stripe_card_token attr_accessible :card_expiration, :card_type, :card_zip, :current_period_end, :current_period_start, :last_four, :next_bill_on, :plan_id, :status, :stripe_customer_token, :trial_end, :trial_start, :user_id belongs_to :plan belongs_to :user end class Relationship &lt; ActiveRecord::Base belongs_to :user belongs_to :location end </code></pre> <p><strong>Controllers</strong></p> <pre><code>class StaticPagesController &lt; ApplicationController def home end def signup @user = User.new @plan = Plan.find_by_identifier("basic_monthly") @location = @user.locations.build @subscription = Subscription.new end def thankyou end end class SubscriptionsController &lt; ApplicationController def create @subscription = Subscription.new params[:subscription] @user = User.create! params[:user] @subscription.user = @user @user.locations &lt;&lt; Location.create!(params[:location]) @plan = Plan.find params[:subscription][:plan_id] if @subscription.save redirect_to thankyou_path else render template: 'static_pages#signup' end end end </code></pre> <p><strong>Signup Form</strong></p> <pre><code>&lt;%= form_for @user, :url =&gt; subscriptions_path(@user) do |user_form| %&gt; First name : &lt;%= user_form.text_field :first_name %&gt;&lt;br /&gt; Last name : &lt;%= user_form.text_field :last_name %&gt;&lt;br /&gt; Email : &lt;%= user_form.email_field :email %&gt;&lt;br /&gt; Phone Number : &lt;%= user_form.phone_field :phone_number %&gt;&lt;br /&gt; Password : &lt;%= user_form.password_field :password %&gt;&lt;br /&gt; Password Confirmation : &lt;%= user_form.password_field :password_confirmation %&gt;&lt;br /&gt; &lt;%= fields_for @location do |location_fields| %&gt; Business Name : &lt;%= location_fields.text_field :name %&gt;&lt;br /&gt; Street Address : &lt;%= location_fields.text_field :street_address %&gt;&lt;br /&gt; Address Line 2 : &lt;%= location_fields.text_field :address_line_2 %&gt;&lt;br /&gt; City : &lt;%= location_fields.text_field :city %&gt;&lt;br /&gt; State : &lt;%= location_fields.text_field :state %&gt;&lt;br /&gt; Zip : &lt;%= location_fields.text_field :zip %&gt;&lt;br /&gt; Website : &lt;%= location_fields.url_field :website %&gt;&lt;br /&gt;&lt;br /&gt; &lt;% end %&gt; &lt;%= fields_for @subscription do |subscription_field| %&gt; &lt;%= subscription_field.hidden_field :plan_id, value: @plan.id %&gt; &lt;% end %&gt; &lt;%= user_form.submit "Sign up", :class =&gt; 'btn primary large' %&gt; &lt;% end %&gt; </code></pre> <p>Finally... the error thrown from Heroku logs (again, this works perfectly fine on my local machine) <strong>Heroku Error - UPDATED</strong> </p> <pre><code>2012-08-03T21:06:30+00:00 app[web.1]: Started GET "/signup" for 72.177.139.69 at 2012-08-03 21:06:30 +0000 2012-08-03T21:06:30+00:00 app[web.1]: Processing by StaticPagesController#signup as HTML 2012-08-03T21:06:30+00:00 app[web.1]: Plan Load (1.3ms) SELECT "plans".* FROM "plans" WHERE "plans"."identifier" = 'basic_monthly' LIMIT 1 2012-08-03T21:06:30+00:00 app[web.1]: Rendered static_pages/signup.html.erb within layouts/application (8.0ms) 2012-08-03T21:06:30+00:00 app[web.1]: Rendered layouts/_shim.html.erb (0.0ms) 2012-08-03T21:06:30+00:00 app[web.1]: Rendered layouts/_navigation.html.erb (1.3ms) 2012-08-03T21:06:30+00:00 app[web.1]: Rendered layouts/_messages.html.erb (0.1ms) 2012-08-03T21:06:30+00:00 app[web.1]: Rendered layouts/_footer.html.erb (0.2ms) 2012-08-03T21:06:30+00:00 app[web.1]: Rendered layouts/_analytics.html.erb (0.0ms) 2012-08-03T21:06:30+00:00 app[web.1]: Completed 200 OK in 458ms (Views: 52.2ms | ActiveRecord: 76.5ms) 2012-08-03T21:06:30+00:00 heroku[router]: GET www.myappname.com/signup dyno=web.1 queue=0 wait=0ms service=470ms status=200 bytes=7555 2012-08-03T21:07:02+00:00 app[web.1]: 2012-08-03T21:07:02+00:00 app[web.1]: 2012-08-03T21:07:02+00:00 app[web.1]: Started POST "/subscriptions" for 72.177.139.69 at 2012-08-03 21:07:02 +0000 2012-08-03T21:07:03+00:00 app[web.1]: 2012-08-03T21:07:03+00:00 app[web.1]: NoMethodError (undefined method `name' for #&lt;User:0x00000003f13a30&gt;): 2012-08-03T21:07:03+00:00 app[web.1]: app/controllers/subscriptions_controller.rb:5:in `create' 2012-08-03T21:07:03+00:00 app[web.1]: 2012-08-03T21:07:03+00:00 app[web.1]: 2012-08-03T21:07:03+00:00 app[web.1]: Processing by SubscriptionsController#create as HTML 2012-08-03T21:07:03+00:00 app[web.1]: Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"ahRL7xz6NE72fxib+KxEX9BVue/NCmS1dSLXSv66alc=", "user"=&gt;{"first_name"=&gt;"Big", "last_name"=&gt;"Boy", "email"=&gt;"example@gmail.com", "phone_number"=&gt;"123456", "password"=&gt;"[FILTERED]", "password_confirmation"=&gt;"[FILTERED]"}, "location"=&gt;{"name"=&gt;"Drew's American Grille", "street_address"=&gt;"123 Physical Address", "address_line_2"=&gt;"", "city"=&gt;"San Antonio", "state"=&gt;"Texas", "zip"=&gt;"78209", "website"=&gt;""}, "subscription"=&gt;{"plan_id"=&gt;"1"}, "commit"=&gt;"Sign up"} 2012-08-03T21:07:03+00:00 app[web.1]: (0.7ms) BEGIN 2012-08-03T21:07:03+00:00 app[web.1]: User Exists (1.5ms) SELECT 1 FROM "users" WHERE "users"."email" = 'example@gmail.com' LIMIT 1 2012-08-03T21:07:03+00:00 app[web.1]: CACHE (0.0ms) SELECT 1 FROM "users" WHERE "users"."email" = 'example@gmail.com' LIMIT 1 2012-08-03T21:07:03+00:00 app[web.1]: (0.6ms) ROLLBACK 2012-08-03T21:07:03+00:00 app[web.1]: Completed 500 Internal Server Error in 100ms 2012-08-03T21:07:03+00:00 heroku[router]: POST www.myappname.com/subscriptions dyno=web.1 queue=0 wait=0ms service=134ms status=500 bytes=643 2012-08-03T21:07:03+00:00 heroku[router]: GET www.myappname.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=5ms status=304 bytes=0 </code></pre> <p>I can upload a schema if need be but essentially it's as follows: <strong>Mini version of schema</strong></p> <pre><code>users email first_name last_name phone_number &lt;normal devise handlers&gt; ... subscriptions user_id plan_id ... relationships user_id location_id locations (all :null =&gt; false) name street_address city state zip ... </code></pre> <p><strong>Also heroku run rake db:migrate doesn't work</strong> It throws a "database configuration does not specify adapter" exception, but Heroku overwrites the database.yml file so why would this occur?</p> <pre><code>Running `rake db:migrate --trace` attached to terminal... up, run.1 ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Invoke db:load_config (first_time) ** Invoke rails_env (first_time) ** Execute rails_env ** Execute db:load_config ** Execute db:migrate ** Invoke db:_dump (first_time) ** Execute db:_dump ** Invoke db:schema:dump (first_time) ** Invoke environment ** Invoke db:load_config ** Execute db:schema:dump rake aborted! database configuration does not specify adapter /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/railties/databases.rake:356:in `block (4 levels) in &lt;top (required)&gt;' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/railties/databases.rake:355:in `open' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/railties/databases.rake:355:in `block (3 levels) in &lt;top (required)&gt;' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' /usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/railties/databases.rake:161:in `block (2 levels) in &lt;top (required)&gt;' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' /usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/railties/databases.rake:156:in `block (2 levels) in &lt;top (required)&gt;' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' /usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `&lt;top (required)&gt;' /app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `load' /app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `&lt;main&gt;' Tasks: TOP =&gt; db:schema:dump </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload