I tend to not need the mass-assignment feature in my production code. (In my test code, I use it a lot, but in those cases I do want to set arbitrary columns.)
So if, in my production code, I simply avoid these forms:
Article.new(params[:article]) # or create
article.attributes = params[:article]
article.update_attributes(params[:article])
and instead always manually enumerate all the attributes, like so:
Article.new(:title => params[:article][:title], :body => params[:article][:body], ...)
am I save from mass assignment security issues (even without using attr_accessible
/attr_protected
)?
Edit: The reason I'm not just disabling mass assignment is, I'd like to be able to write Article.create!(:blog_id => @blog.id, ...)
, where blog_id is an "unsave" attribute.