Re: exclude an attribute from save

Raphael Bauduin
Mon, 07 Mar 2005 16:13:57 -0000

On Mon, 7 Mar 2005 17:08:01 +0100, Enrico Teotti
<agenteo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> Hi,
> I''ve used .save to save the attributes, but on my table there is
an
> autoincrementing id (not the primary key) that doesn''t need to be
> inserted... but save try to INSERT it anyway... is there a way to
> avoid save from acting this way or to whisper him to be more polite
> this time? ;)
> Thanks,
> Enrico
>


I just read this over at
http://wiki.rubyonrails.com/rails/show/HowtoUsePostgresViewsAsTables .

I havent tried it, just read it minutes before seeing your mail.

Raph

Active Record doesn''t have support for making columns read-only, but
you can simulate the effect by using attr_protected and defining empty
writer methods:

require ''active_record''

class Quote < ActiveRecord::Base
  attr_protected :score, :votes, :activity
  def score=(ignored) end
  def votes=(ignored) end
  def activity=(ignored) end
end







> --
> "The only thing necessary for the triumph of evil
> is for good men to do nothing"
>  Edmund Burke
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>