Re: Read only model attributes

Wiebe Cazemier
Thu, 27 Oct 2005 22:38:18 -0000

Jeremy Kemper wrote:
> Yup!
>
> class Foo
>   def bar=(value)
>     raise "I''m read-only dammit!"
>   end
> end

I''ve got a question about something related. When you override the
"=" operator
like this, is it still necessary to protect against mass assignments with
"attr_protected"? In other words, does assigning like
"model.attributes = hash"
use the "=" operator, or does it generate SQL itself?

I''m pretty sure it is the former, but thought I''d ask, just to
be sure.