Rails3 设计未定义的方法`confirmation_url' [英] Rails3 Devise undefined method `confirmation_url'

查看:11
本文介绍了Rails3 设计未定义的方法`confirmation_url'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎已经为我的用户身份验证设置了 Devise,并设置了 :confirmable 选项.

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

当我在浏览器中运行它时,一切似乎都运行良好,我注册,转到我的 rails s 控制台中服务器日志中显示的确认 URL.

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.

但是,当我尝试将以下内容添加到我的 db/seed.rb

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

User.create!(:username => 'haar', :email => 'haar@example.com', :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

知道是什么原因造成的以及如何解决吗?

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" }

在 Ruby 1.8.7、Rails 3.0.8、设计 1.4.5 上运行.

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

推荐答案

结果很简单,当我运行 rails generate devise:views 时,与路由 相比,它生成了错误的路径devise_for :user 生成.它还产生了一些其他问题,例如 user_confirmation_url 指向@resource,作为第一个参数;当它不应该有的时候.

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).

这篇关于Rails3 设计未定义的方法`confirmation_url'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆