Hi all. I''ve the following comments'' model: class Comment < ActiveRecord::Base validates_presence_of :commentary, :anon belongs_to :commentary, :polymorphic => true attr_accessor :anon #anon is an virtual attribute. before_save :anonymize protected def anonymize if self.anon == 1 self.author = "Anonymous" self.email = "anonymous-ps1yJmh03mYq8ddH4TG6mw@public.gmane.org" end end end If I bring up my console:>> c = Comment.new=> #<Comment id: nil, commentary_id: nil, commentary_type: nil, author: nil, email: nil, comment: nil, created_at: nil, updated_at: nil>>> c.author = "foo"=> "foo">> c.email = "bar"=> "bar">> c.commentary_type = "Article"; c.commentary_id = 6=> 6>> c.anon = 1=> 1>> c.save!=> true>> c=> #<Comment id: 26, commentary_id: 6, commentary_type: "Article", author: "Anonymous", email: "anonymous-ps1yJmh03mYq8ddH4TG6mw@public.gmane.org", comment: nil, created_at: "2008-11-01 22:18:06", updated_at: "2008-11-01 22:18:06"> All works fine. But it doesn''t work from my view: http://pastie.org/305633 From my view, it saves using comment_author.value and comment_email.value. What am I missing? Best regards, -- Davi Vidal -- E-mail: davividal arroba siscompar ponto com ponto br MSN : davividal arroba msn ponto com GTalk : davividal arroba gmail ponto com Skype : davividal YIM : davi_vidal ICQ : 138815296 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1 Nov 2008, at 22:46, Davi Vidal <davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org> wrote:> > > Hi all. I''ve the following comments'' model: > > class Comment < ActiveRecord::Base > validates_presence_of :commentary, :anon > > belongs_to :commentary, :polymorphic => true > > attr_accessor :anon #anon is an virtual attribute. > > before_save :anonymize > > protected > def anonymize > if self.anon == 1 > self.author = "Anonymous" > self.email = "anonymous-ps1yJmh03mYq8ddH4TG6mw@public.gmane.org" > end > end > end > > If I bring up my console: > >>> c = Comment.new > => #<Comment id: nil, commentary_id: nil, commentary_type: nil, > author: nil, > email: nil, comment: nil, created_at: nil, updated_at: nil> >>> c.author = "foo" > => "foo" >>> c.email = "bar" > => "bar" >>> c.commentary_type = "Article"; c.commentary_id = 6 > => 6 >>> c.anon = 1 > => 1 >>> c.save! > => true >>> c > => #<Comment id: 26, commentary_id: 6, commentary_type: "Article", > author: > "Anonymous", email: "anonymous-ps1yJmh03mYq8ddH4TG6mw@public.gmane.org", comment: nil, created_at: > "2008-11-01 22:18:06", updated_at: "2008-11-01 22:18:06"> > > All works fine. But it doesn''t work from my view: > > http://pastie.org/305633 > > From my view, it saves using comment_author.value and > comment_email.value. > What am I missing? >anon will be the string "1" and not the integer 1 Fred> > Best regards, > -- > Davi Vidal > -- > E-mail: davividal arroba siscompar ponto com ponto br > MSN : davividal arroba msn ponto com > GTalk : davividal arroba gmail ponto com > Skype : davividal > YIM : davi_vidal > ICQ : 138815296 > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Saturday 01 November 2008 21:11:59 Frederick Cheung wrote:> On 1 Nov 2008, at 22:46, Davi Vidal <davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org> wrote:[...]> > From my view, it saves using comment_author.value and > > comment_email.value. > > What am I missing? > > anon will be the string "1" and not the integer 1 >Ops! Lack of coffee. :-) Thank you very much, Fred. Changed from "self.anon" to "self.anon.to_i". -- Davi Vidal -- E-mail: davividal arroba siscompar ponto com ponto br MSN : davividal arroba msn ponto com GTalk : davividal arroba gmail ponto com Skype : davividal YIM : davi_vidal ICQ : 138815296 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---