2

私は答えを高低で探してきましたが、立ち往生しています。ローカルの開発環境ではすべてが機能しますが、本番環境 (Heroku) ではすべてが失敗します。同じデータベース (postgres) を使用します。Heroku は NoMethodError を爆発させますが、そのメソッドに送信しているとは思えません。

メインの 3 つのモデル (追加の結合モデル)、3 つのモデルすべてに送信する has_many を持つネストされたフォームが 1 つあり、Static_Pages#signup (新しいアクションとして機能) と問題が発生している Subscriptions_Controller#create があります。

モデル

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 run 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
4

1 に答える 1

0

私はばかげた愚かな間違いを犯しました (Ruby とプログラミング全般ではまだ新しいものです)。私は、他のエラーと競合して生成されたという以前のモデルを持ってold_user.rbいました。何らかの理由で、私の開発マシンのロード順序が Heroku のロード順序と異なっていたのではないかと思います。class User < ActiveRecord::Baseuser.rb

于 2012-08-06T19:25:40.463 に答える