【问题标题】:"Can't find mapping" error in Rails (when using Devise Gem)?Rails 中的“找不到映射”错误(使用 Devise Gem 时)?
【发布时间】:2015-06-05 17:10:42
【问题描述】:

我正在使用 Devise 对用户进行身份验证。我正在尝试制作一个表单/更新方法来更新密码。表单生成正确,它也选择了路线。但是,我收到以下错误:

“找不到路径“/users/updatepw”的设计映射。这可能有两个原因:1)您忘记将路由包装在范围块内。例如:devise_scope :user do get "/some/ route" => "some_devise_controller" end 2) 您正在测试绕过路由器的 Devise 控制器。如果是这样,您可以明确告诉 Devise 要使用哪个映射:@request.env["devise.mapping"] = Devise.mappings[:用户]"

第一个选项似乎不是原因,这是我的routes.rb:

devise_scope :users do
  ...
  post "/users/updatepw", to: "users/registrations#update_password", as :update_pw
  ...  
end
...
resources :users #I don't know if this is needed considering the devise block, but commenting it out doesn't fix the problem..

所以它包装了。

至于第二个选项...我不是很明白...我不想测试任何东西...?

我的问题实际上是 2 倍: 1)考虑到我没有尝试运行任何测试,错误是什么意思? 2) 我在哪里放置纠正行 ("@request.env["devise.mapping"] = Devise.mappings[:user]") 来解决问题?

【问题讨论】:

    标签: ruby-on-rails ruby devise


    【解决方案1】:

    我认为您的表单中缺少as: resource_name 选项。查看 Devise 的密码编辑

    <%= form_for(resource, as: resource_name, ...

    https://github.com/plataformatec/devise/blob/master/app/views/devise/passwords/edit.html.erb#L3

    问题:您为什么要创建自己的更新密码?设计已经提供了这个。

    【讨论】:

      猜你喜欢
      • 2018-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-22
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多