1

I have a simple statement like this:

@employee.update_attributes(:subscribed=>false)

but this is not updating the boolean column field subscribed. It throws a warning saying:

WARNING: Can't mass-assign these protected attributes: subscribed

2 Answers 2

3

I would suggest using #update_attribute, not #update_attributes. #update_attribute (singular) accepts two parameters: the attribute name and the value. This is intended for flipping booleans, or updating single values. The semantics of #update_attribute also mean that callbacks won't be fired.

From your code, it's a simple change:

@employee.update_attribute(:subscribed, false)

Now, for the real reason why your code is failing is because you have someplace where you're using #attr_accessible or #attr_protected in your Employee model. Using #attr_accessible helps prevent injection attacks by only allowing certain fields to be assignable from #attributes= (which is what #update_attributes ultimately calls). The warning originates from #attributes=.

Sign up to request clarification or add additional context in comments.

Comments

1

needed attr_accessible :subscribed >_<

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.