【发布时间】:2012-04-16 16:58:27
【问题描述】:
我正在关注 Railstutorial.org 并在使用 Rspec 时遇到 MassAssignment 错误。
10) User when email format is invalid should be invalid
Failure/Error: @user = User.new(name:"Example", email:"example@gmail.com",
ActiveModel::MassAssignmentSecurity::Error:
Can't mass-assign protected attributes: password, password_confirmation
可能是因为我尝试在 RSpec 中分配 before 变量:
...
before do
@user = User.new(name:"Example", email:"example@gmail.com",
password: "foobar", password_confirmation: "foobar" )
end
subject { @user }
...
是否可以在开发或测试模式下禁用 MassAssignment 保护?或者当 RSpec 运行时? 任何帮助都会很棒!谢谢
【问题讨论】:
-
当这些属性被标记为可以批量分配时,此错误将在本教程稍后得到修复:“attr_accessible :name, :email, :password, :password_confirmation”。 (ruby.railstutorial.org/chapters/…)
标签: ruby-on-rails-3 rspec railstutorial.org mass-assignment