Is there a way to bypass mass assignment protection?

前端 未结 3 1381
余生分开走
余生分开走 2020-12-28 16:46

I have a Rails 3 app which JSON encodes objects in order to store them in a Redis key/value store.

When I retrieve the objects, I\'m trying to decode the JSON and in

3条回答
  •  自闭症患者
    2020-12-28 17:13

    assign_attributes with without_protection: true seems less intrusive:

    user = User.new
    user.assign_attributes({ :name => 'Josh', :is_admin => true }, :without_protection => true)
    user.name       # => "Josh"
    user.is_admin?  # => true
    

    @tovodeverett mentioned in the comment you can also use it with new, like this in 1 line

    user = User.new({ :name => 'Josh', :is_admin => true }, :without_protection => true)
    

提交回复
热议问题