Rails 4.0&设计 - 强参数错误 [英] Rails 4.0 & Devise - Strong Parameters error

查看:156
本文介绍了Rails 4.0&设计 - 强参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



新的应用程序在Rails 4与ruby 2.0,我安装了Devise并按照说明(默认root等) 。 github的Devise自述表示应该与rails4兼容,但是




  • db:migrate失败,除非我在User.rb中注释掉attr_accessible行

  • 在评论之后,尝试创建用户时,会得到Devise :: RegistrationsController#create中的ActiveModel :: ForbiddenAttributesError错误。



我看到一些这样的堆栈溢出问题,但很多答案直接进入了一些复杂的谈话。我得到我需要指定允许的质量分配的属性,但是如何?在哪里?哪些属性需要被允许,所有这些?只有那些我希望在同一时间更改/创建的那些?



根据错误判断,我将创建一个从Devise :: registrationsController继承的registrations_controller.rb?我在这里指定了什么?



任何一步一步,新手友好的答案都非常感激。我已经用尽了不同的代码,从这里的答案和谷歌搜索的各种网站。

解决方案

欢迎来到stackoverflow! >

问题是attr_accessible的功能在rails 4.0中更改



有可能使其运行



1更新它可以处理Rails 4.0的设计



将此行添加到应用程序的Gemfile中:

  gem'devise','3.0.0.rc'

然后执行:

  $ bundle 
pre>

2将attr_accessible的旧功能再次添加到rails 4.0



尝试使用attr_accessible,不要对此进行评论



将此行添加到应用程序的Gemfile中:

  gem 'protected_attributes'

然后执行:

  $ bundle 


Newbie to rails here, so bear with me.

New app on Rails 4 with ruby 2.0, I installed Devise and followed the instructions(default root, etc). Devise readme on github says it should be compatible with rails4 but

  • db:migrate failed unless I commented out attr_accessible line in User.rb
  • After commenting that out, I get "ActiveModel::ForbiddenAttributesError in Devise::RegistrationsController#create" error in trying to create a user.

I see some stack overflow questions like this, but a lot of the answers jump straight into some complex talk. I get I need to specify permitted attributes for mass assignment, but how? And where? And which attributes need to be permitted, all of them? Only those that I expect to be changed/created at the same time?

Judging by the error would I create a registrations_controller.rb that inherits from Devise::registrationsController ? What do I specify in that?

Any step by step, newbie friendly answers are much appreciated. I've exhausted myself trying different code from answers here and various sites from google searches.

解决方案

Welcome to stackoverflow!

The problem is that the functinality of attr_accessible changed in rails 4.0

2 possibilities to get it running

1 Update Devise that it can handle Rails 4.0

Add this line to your application's Gemfile:

gem 'devise', '3.0.0.rc' 

And then execute:

$ bundle

2 Add the old functionality of attr_accessible again to rails 4.0

Try to use attr_accessible and dont comment this out.

Add this line to your application's Gemfile:

gem 'protected_attributes'

And then execute:

$ bundle

这篇关于Rails 4.0&设计 - 强参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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