设计参数消毒器“ For”。方法未找到Rails 5 [英] Devise Parameter Sanitizer "For" Method Not Found Rails 5

查看:44
本文介绍了设计参数消毒器“ For”。方法未找到Rails 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将设计添加到了闪亮的新Rails 5应用中。一切顺利,直到我尝试为Devise用户模型添加用户名。一切正常,直到我运行它并转到 localhost:3000 / users / sign_up ,在那里我受到了欢迎错误:

I have just added devise to my shiny new Rails 5 app. All's good and dandy until I try to add a username to the Devise user model. Everything worked until I ran it and went to localhost:3000/users/sign_up, where I was greeted by this error:

undefined method `for' for #<Devise::ParameterSanitizer:0x007fa0dc31c1b0> Did you mean? fork

我已经在Google的绝佳位置搜索了任何结果,但结果却被过时了,Rails 4错误和解决方案,与搜索Stack Overflow本身相同。我无法找到可行的解决方案。非常感谢您的帮助。这是我为此准备的方法:

I have searched the wonderful place of Google for any results, only being given outdated, Rails 4 errors and solutions, the same with searching Stack Overflow itself. I cannot get my mind to find a working solution. I would appreciate help very much. Here is how I prepared for this:


  1. 创建迁移: rails生成迁移add_username_to_users用户名:string:uniq

  2. 迁移数据库 rake db:migrate

  3. 添加强大应用程序控制器的参数 devise_parameter_sanitizer.for(:sign_up){| u | u.permit(..)}

  4. 将用户名参数添加到设计视图中

  5. 重新启动服务器

  1. Create the migration: rails generate migration add_username_to_users username:string:uniq
  2. Migrate the database rake db:migrate
  3. Add strong parameters to the application controller devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(..) }
  4. Add username parameters to the Devise views
  5. Restart the server

是否有任何我错过或做错的事情?

Is there anything I missed or did wrong?

推荐答案

.for方法从devise 4.1起已弃用。.permit方法可用

The .for method is deprecated, from devise 4.1+ .permit method is available

尝试 .permit。应该可以。

devise_parameter_sanitizer.permit(:my_action) { |u| u.permit(..) }

希望这对您有帮助:)

这篇关于设计参数消毒器“ For”。方法未找到Rails 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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