Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

ruby on rails - Rails3 Devise undefined method `confirmation_url'

I've seemingly set up Devise for my User authentication, with the :confirmable option set.

Everything seems to run fine when I run it in the browser, I sign up, go to the confirmation url shown in the server log in my rails s console.

However, when I try to add the following to my db/seed.rb

User.create!(:username => 'haar', :email => '[email protected]', :password => 'password', :password_confirmation => 'password')

And run rake db:setup --trace

I get the following error:

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

Any idea what's causing this and how to resolve it?

I have the following line included in my test environment, for the record:

config.action_mailer.default_url_options = { :host => "localhost:3000" }

Running on Ruby 1.8.7, Rails 3.0.8, with devise 1.4.5.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It simply turned out that when I ran rails generate devise:views, it generated incorrect paths when compared to the routes devise_for :user generated. It also generated some other issues, such as the user_confirmation_url pointing to @resource, as the first parameter; when it shouldn't have.

(I didn't want the question to be left unanswered, I'm unsure as to the typical etiquette. If I'm wrong in doing this, please let me know).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...