Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何修复rails中Desive的批量分配安全错误?_Ruby On Rails_Authentication_Devise - Fatal编程技术网

Ruby on rails 如何修复rails中Desive的批量分配安全错误?

Ruby on rails 如何修复rails中Desive的批量分配安全错误?,ruby-on-rails,authentication,devise,Ruby On Rails,Authentication,Devise,我正在Rails应用程序中使用Desive进行身份验证。当我尝试以用户身份注册时,会出现一个错误,提示:无法批量分配受保护的属性:电子邮件、密码、密码确认。直到我在Users表中添加了一个名为“owner”的新列,我才收到此错误 User.rb class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable

我正在Rails应用程序中使用Desive进行身份验证。当我尝试以用户身份注册时,会出现一个错误,提示:无法批量分配受保护的属性:电子邮件、密码、密码确认。直到我在Users表中添加了一个名为“owner”的新列,我才收到此错误

User.rb

class User < ActiveRecord::Base
    devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable   
    attr_accessible :owner, :email, :password, :password_confirmation, :admin, :as => :admin    
end
class用户:管理员
结束
迁移以添加用户:

class AddOwnerToUsers < ActiveRecord::Migration
  def change
    add_column :users, :owner, :boolean, :default => false
  end
end
class AddOwnerToUsersfalse
结束
结束

在我加上:业主,我不记得有这个问题。关于如何解决这个问题,有什么建议吗?

我不太清楚
属性中的
:as
的用法。我从来没用过。据我所知,在更新体量属性时,必须指定以下内容:

User.new(params[:user], :as => :admin)
或者


我在
用户
模型中看到了问题。在我们的源文件中也是这样吗?@HungryCoder我忘了包括一行,现在已经添加了。你还看到User.rb中有问题吗?嗯,我还是会出错(我只是在第一次发表文章时不小心删除了那一行)。
@user = User.find(1)
@user.update_attributes(params[:user], :as => :admin)