Supose that I have the following class:
class Foo < ActiveRecord::Base
belongs_to :bar
end
In rails console I can do this:
foo = Foo.new
foo.bar_id = 3
But this can violates the encapsulation principle. I think that is better idea do:
foo = Foo.new
foo.bar = Bar.find(3);
And bar_id
should be private/protected.
This has nothing to do with the mass assignment
and strong parameters
but it is an security issue too.
Is there any way to set to private some attributes?