相关疑难解决方法(0)

无法批量分配受保护的属性

我的features文件看这个:

Given there are the following users:
    | email              | password | admin |
    | admin@ticketee.com | password | true  |
Run Code Online (Sandbox Code Playgroud)

并且我的user模型没有声明admin属性attr_accessible以防止批量分配.因此,我已对user_steps.rb文件进行了更改以解决此问题.

Given /^there are the following users:$/ do |table|
  table.hashes.each do |attributes|
   unconfirmed = attributes.delete("unconfirmed") == "true"
   @user = User.create!(attributes)
   @user.update_attribute("admin", attributes["admin"] == "true")
   @user.confirm! unless unconfirmed
 end
end
Run Code Online (Sandbox Code Playgroud)

现在这应该按照书中的说法--Rails3在行动.我也检查了他们在线仓库的代码.用黄瓜运行它会产生以下错误:

Can't mass-assign protected attributes: admin (ActiveModel::MassAssignmentSecurity::Error)
  ./features/step_definitions/user_steps.rb:4:in `block (2 levels) in <top (required)>'
  ./features/step_definitions/user_steps.rb:2:in `each'
  ./features/step_definitions/user_steps.rb:2:in `/^there are the …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails cucumber

4
推荐指数
1
解决办法
9626
查看次数

标签 统计

cucumber ×1

ruby-on-rails ×1