:confirmableオプションを設定して、ユーザー認証用にDeviseを設定したようです。
ブラウザで実行すると、すべて正常に動作しているようです。サインアップして、Rails s
コンソールのサーバーログに表示される確認URLに移動します。
ただし、db /seed.rbに以下を追加しようとすると
User.create!(:username => 'haar', :email => '[email protected]', :password => 'password', :password_confirmation => 'password')
そして、rake db:setup --trace
を実行します
次のエラーが発生します。
rake aborted!
undefined method `confirmation_url' for #<#<Class:0x1062f79a0>:0x1062f6618>
/Users/haar/Dropbox/Websites/TenOutOfTen/app/views/devise/mailer/confirmation_instructions.html.haml:4:in `_app_views_devise_mailer_confirmation_instructions_html_haml___1737567023_2199377480_0'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/action_view/template.rb:135:in `send'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/action_view/template.rb:135:in `render'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activesupport-3.0.8/lib/active_support/notifications.rb:54:in `instrument'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/action_view/template.rb:127:in `render'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/action_view/render/rendering.rb:59:in `_render_template'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activesupport-3.0.8/lib/active_support/notifications.rb:52:in `instrument'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activesupport-3.0.8/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activesupport-3.0.8/lib/active_support/notifications.rb:52:in `instrument'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/action_view/render/rendering.rb:56:in `_render_template'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/action_view/render/rendering.rb:26:in `render_without_haml'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/haml-3.1.3/lib/haml/helpers/action_view_mods.rb:13:in `render'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/abstract_controller/rendering.rb:115:in `_render_template'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/abstract_controller/rendering.rb:109:in `render_to_body'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/abstract_controller/rendering.rb:102:in `render_to_string'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/abstract_controller/rendering.rb:93:in `render'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionmailer-3.0.8/lib/action_mailer/deprecated_api.rb:111:in `render'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionmailer-3.0.8/lib/action_mailer/base.rb:735:in `collect_responses_and_parts_order'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionmailer-3.0.8/lib/action_mailer/base.rb:750:in `each'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionmailer-3.0.8/lib/action_mailer/base.rb:750:in `each_template'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionmailer-3.0.8/lib/action_mailer/base.rb:745:in `each'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionmailer-3.0.8/lib/action_mailer/base.rb:745:in `each_template'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionmailer-3.0.8/lib/action_mailer/base.rb:731:in `collect_responses_and_parts_order'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionmailer-3.0.8/lib/action_mailer/base.rb:673:in `mail'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/devise-1.4.5/lib/devise/mailers/helpers.rb:21:in `devise_mail'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/devise-1.4.5/app/mailers/devise/mailer.rb:5:in `confirmation_instructions'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/abstract_controller/base.rb:150:in `send_action'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/abstract_controller/base.rb:150:in `process_action'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/abstract_controller/base.rb:119:in `process'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/abstract_controller/rendering.rb:41:in `process'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionmailer-3.0.8/lib/action_mailer/old_api.rb:75:in `process'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionmailer-3.0.8/lib/action_mailer/base.rb:471:in `process'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionmailer-3.0.8/lib/action_mailer/base.rb:466:in `initialize'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionmailer-3.0.8/lib/action_mailer/base.rb:450:in `new'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/actionmailer-3.0.8/lib/action_mailer/base.rb:450:in `method_missing'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/devise-1.4.5/lib/devise/models/confirmable.rb:50:in `send_confirmation_instructions'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activesupport-3.0.8/lib/active_support/callbacks.rb:423:in `_run_create_callbacks'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/callbacks.rb:277:in `create'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/persistence.rb:250:in `create_or_update'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/callbacks.rb:273:in `create_or_update'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activesupport-3.0.8/lib/active_support/callbacks.rb:419:in `_run_save_callbacks'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/callbacks.rb:273:in `create_or_update'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/persistence.rb:60:in `save!'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/validations.rb:49:in `save!'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/transactions.rb:245:in `save!'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/transactions.rb:292:in `with_transaction_returning_status'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/transactions.rb:207:in `transaction'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/transactions.rb:245:in `save!'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/validations.rb:34:in `create!'
/Users/haar/Dropbox/Websites/TenOutOfTen/db/seeds.rb:7
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activesupport-3.0.8/lib/active_support/dependencies.rb:235:in `load'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activesupport-3.0.8/lib/active_support/dependencies.rb:235:in `load'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activesupport-3.0.8/lib/active_support/dependencies.rb:225:in `load_dependency'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activesupport-3.0.8/lib/active_support/dependencies.rb:596:in `new_constants_in'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activesupport-3.0.8/lib/active_support/dependencies.rb:225:in `load_dependency'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activesupport-3.0.8/lib/active_support/dependencies.rb:235:in `load'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/activerecord-3.0.8/lib/active_record/railties/databases.rake:281
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/Users/haar/.rvm/rubies/Ruby-1.8.7-p334/lib/Ruby/1.8/monitor.rb:242:in `synchronize'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:176:in `invoke_prerequisites'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:174:in `each'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:157:in `invoke_with_call_chain'
/Users/haar/.rvm/rubies/Ruby-1.8.7-p334/lib/Ruby/1.8/monitor.rb:242:in `synchronize'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:62:in `run'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/gems/rake-0.9.2/bin/rake:32
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/bin/rake:19:in `load'
/Users/haar/.rvm/gems/Ruby-1.8.7-p334/bin/rake:19
Tasks: TOP => db:setup => db:seed
これを引き起こしている原因とそれを解決する方法について何か考えはありますか?
記録のために、テスト環境に次の行が含まれています。
config.action_mailer.default_url_options = { :Host => "localhost:3000" }
Ruby 1.8.7、Rails 3.0.8、デバイス1.4.5を使用。
Rails generate devise:views
を実行すると、devise_for :user
が生成したルートと比較して、誤ったパスが生成されたことがわかりました。また、最初のパラメーターとして@resourceを指すuser_confirmation_url
など、他のいくつかの問題も発生しました。あるべきではないとき。
(質問に答えられないままにしたくなかったので、典型的なエチケットについてはよくわかりません。これを間違えた場合は、お知らせください)。
サーバーを再起動するだけでも同じ問題が発生し、このエラーは削除されました。
cTRL + cを実行してから、Rails sを使用してサーバーを起動します。
さらに、私がそうであるように、DeviseモデルでSTIを使用している場合は、type属性を介して確認できます。したがって、私のコードは次のようになります。
<p><%= link_to 'Confirm my account', manager_confirmation_url(:confirmation_token => @resource.confirmation_token) if @resource.type == 'Manager' %></p>
<p><%= link_to 'Confirm my account', subscriber_confirmation_url(:confirmation_token => @resource.confirmation_token) if @resource.type == 'Subscriber' %></p>