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.
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.
Models
class Location < 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 => :relationships
end
class User < ActiveRecord::Base
has_one :subscription
has_one :plan, :through => :subscription
has_many :relationships
has_many :locations, :through => :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 < 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 < ActiveRecord::Base
belongs_to :user
belongs_to :location
end
Controllers
class StaticPagesController < 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 < ApplicationController
def create
@subscription = Subscription.new params[:subscription]
@user = User.create! params[:user]
@subscription.user = @user
@user.locations << 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
Signup Form
<%= form_for @user, :url => subscriptions_path(@user) do |user_form| %>
First name : <%= user_form.text_field :first_name %><br />
Last name : <%= user_form.text_field :last_name %><br />
Email : <%= user_form.email_field :email %><br />
Phone Number : <%= user_form.phone_field :phone_number %><br />
Password : <%= user_form.password_field :password %><br />
Password Confirmation : <%= user_form.password_field :password_confirmation %><br />
<%= fields_for @location do |location_fields| %>
Business Name : <%= location_fields.text_field :name %><br />
Street Address : <%= location_fields.text_field :street_address %><br />
Address Line 2 : <%= location_fields.text_field :address_line_2 %><br />
City : <%= location_fields.text_field :city %><br />
State : <%= location_fields.text_field :state %><br />
Zip : <%= location_fields.text_field :zip %><br />
Website : <%= location_fields.url_field :website %><br /><br />
<% end %>
<%= fields_for @subscription do |subscription_field| %>
<%= subscription_field.hidden_field :plan_id, value: @plan.id %>
<% end %>
<%= user_form.submit "Sign up", :class => 'btn primary large' %>
<% end %>
Finally... the error thrown from Heroku logs (again, this works perfectly fine on my local machine) Heroku Error - UPDATED
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 #<User:0x00000003f13a30>):
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"=>"✓", "authenticity_token"=>"ahRL7xz6NE72fxib+KxEX9BVue/NCmS1dSLXSv66alc=", "user"=>{"first_name"=>"Big", "last_name"=>"Boy", "email"=>"[email protected]", "phone_number"=>"123456", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "location"=>{"name"=>"Drew's American Grille", "street_address"=>"123 Physical Address", "address_line_2"=>"", "city"=>"San Antonio", "state"=>"Texas", "zip"=>"78209", "website"=>""}, "subscription"=>{"plan_id"=>"1"}, "commit"=>"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" = '[email protected]' LIMIT 1
2012-08-03T21:07:03+00:00 app[web.1]: CACHE (0.0ms) SELECT 1 FROM "users" WHERE "users"."email" = '[email protected]' 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
I can upload a schema if need be but essentially it's as follows: Mini version of schema
users
email
first_name
last_name
phone_number
<normal devise handlers>
...
subscriptions
user_id
plan_id
...
relationships
user_id
location_id
locations (all :null => false)
name
street_address
city
state
zip
...
Also heroku run rake db:migrate doesn't work It throws a "database configuration does not specify adapter" exception, but Heroku overwrites the database.yml file so why would this occur?
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 <top (required)>'
/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 <top (required)>'
/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 <top (required)>'
/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 <top (required)>'
/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 `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `load'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `<main>'
Tasks: TOP => db:schema:dump
I made a stupid silly mistake (still new at Ruby and programming in general). I had a previous model called old_user.rb
that had class User < ActiveRecord::Base
which conflicted with user.rb
and generated out the other errors. For some reason, I guess the load order on my dev machine was different than Heroku's load order and why I never realized it.