【问题标题】:ActionController::UrlGenerationError in Devise::Registrations#create设计中的 ActionController::UrlGenerationError::Registrations#create
【发布时间】:2015-02-27 23:03:03
【问题描述】:

我是 Rails 的新手,不知道如何处理这个错误,请帮助(解释):

Devise::Registrations#create 中的 ActionController::UrlGenerationError

显示 /home/ubuntu/workspace/mamchut418/app/views/devise/mailer/confirmation_instructions.html.erb 其中第 5 行提出:

没有路由匹配 {:action=>"create", :confirmation_token=>"24GGcednzrEXEzaR82AC", :controller=>"devise/confirmations"} 缺少必需的键:[:locale]

提取的源代码(第 5 行附近):

3 | <p><%= _('You can confirm your account email through the link below:') %>p>
4 |
5 | <p><%= link_to _('Confirm my account'), confirmation_url(@resource, confirmation_token: @token) %></p>

app/views/devise/mailer/confirmation_instructions.html.erb:5:in `_app_views_devise_mailer_confirmation_instructions_html_erb___1326125006769773887_55918960'

请求

参数:

{"utf8"=>"✓",
"authenticity_token"=>"pY7ApWH/WTOVTFGifeV7QbubuNch/EzCJWjaXg7t+i5iYpI=",
"user"=>{"email"=>"qwerty@gmail.com",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]"},
"commit"=>"Registrovať",
"locale"=>"sk"}

会话转储

_csrf_token: "pY7ApWH/WTkukoOVTFGifeV7QNch/EzCJWjaXg7t+i5iYpI="
locale: "sk"
session_id: "01f6f1f89089a5ef29326e80b0d44f79"

【问题讨论】:

    标签: ruby-on-rails devise ruby-on-rails-4.1 rails-i18n devise-confirmable


    【解决方案1】:

    这是一个i18n(国际化)问题,它需要知道 yoru 语言环境是什么。在 config/application.rb 文件中指定国际化的默认语言环境

    config.i18n.default_locale = :en
    

    或者你可能想要斯洛伐克语

    config.i18n.default_locale = :sk
    

    编辑

    你也可以在调用confirmation_url方法的时候指定locale...

    <p><%= link_to _('Confirm my account'), confirmation_url(@resource, confirmation_token: @token, locale: 'en') %></p>
    

    【讨论】:

    • 非常感谢您的建议,我做到了,清除缓存,重新启动服务器,但该错误仍然存​​在 :-(
    • Github 的一个人建议我这样做:-“根据错误,看起来您需要在“confirmation_url”帮助程序上传递“locale”选项,这应该可以工作。” - 也许这是解决方案,但对我来说这是“西班牙村”。我不知道该怎么做。能给我解释一下吗?
    • 他建议您通过传递 locale 选项来更改此行...这是修改后的行...&lt;p&gt;&lt;%= link_to _('Confirm my account'), confirmation_url(@resource, confirmation_token: @token, locale: 'en') %&gt;&lt;/p&gt;
    • 是的......!有用。谢谢。可能需要用当前的语言环境变量替换“en”才能在所有启用的语言环境中正常工作...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    • 2017-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-20
    相关资源
    最近更新 更多