0

let's say, i've got 2 apps which use the same database(app), and i've got a field say: cool, so i want to use this field in first app but not in second. so how to avoid this error Can't mass-assign protected attributes without using attr_accessible in database(app) ?

Said Kaldybaev
  • 9,380
  • 8
  • 36
  • 53

1 Answers1

1

I'm not sure if I understand, but this is what I ususally do:

protected_attribute = params[:blog_post].delete(:protected_attribute)

@blog_post = BlogPost.new(params[:blog_post])
@blog_post.protected_attribute = protected_attribute
if @blog_post.save
  # ...
else
  # ...
end

It's ugly, but circumvents the mass-assign protection.

Update: You also have to remove the protected attribute from the params.

Wukerplank
  • 4,156
  • 2
  • 28
  • 45
  • Right, you also have to remove the attribute from the params. I've updated my answer to reflect the changes. – Wukerplank Jul 06 '12 at 08:00