设计参数消毒器“ For”。方法未找到Rails 5 [英] Devise Parameter Sanitizer "For" Method Not Found 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:
- 创建迁移:
rails生成迁移add_username_to_users用户名:string:uniq
- 迁移数据库
rake db:migrate
- 添加强大应用程序控制器的参数
devise_parameter_sanitizer.for(:sign_up){| u | u.permit(..)}
- 将用户名参数添加到设计视图中
- 重新启动服务器
- Create the migration:
rails generate migration add_username_to_users username:string:uniq
- Migrate the database
rake db:migrate
- Add strong parameters to the application controller
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(..) }
- Add username parameters to the Devise views
- 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屋!