我一直在寻找高低的答案而且我处于停滞状态。一切都在我的本地开发环境中运行,但每一个都在生产(Heroku)上爆炸。使用相同的数据库(postgres)。即使我不相信我曾经发送过那种方法,Heroku也会破坏NoMethodError。
我有3个主要模型(额外的连接模型),一个嵌套的表单有一个has_many:通过提交到所有三个模型,Static_Pages #regupup(充当新的动作)和一个Subscriptions_Controller#创建问题发生的地方。
模型
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
控制器
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
注册表单
<%= 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 %>
最后......从Heroku日志抛出的错误(再次,这在我的本地机器上完全正常) Heroku错误 - 更新
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"=>"example@gmail.com", "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" = '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
如果需要,我可以上传架构,但基本上如下: 架构的迷你版
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
...
此外,heroku运行rake db:migrate不起作用 它抛出“数据库配置没有指定适配器”异常,但是Heroku会覆盖database.yml文件,为什么会发生这种情况呢?
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
答案 0 :(得分:0)
我犯了一个愚蠢的愚蠢错误(在Ruby和编程方面仍然是新的)。我有一个名为old_user.rb
的模型class User < ActiveRecord::Base
与user.rb
冲突,并产生了其他错误。出于某种原因,我猜我的开发机器上的加载顺序与Heroku的加载顺序不同,为什么我从未意识到它。