Greg Hauptmann
2006-Sep-09 22:52 UTC
why doesn''t this work (setting attribute in "before_create")
Hi, Can anyone spot why the below doesn''t work? * I have a "created_by" column in my create table in the dB * I have a "before_create" line, which definitely gets called * I tried a few different ways to set the "created_by" attribute in the model but it doesn''t seem to work, i.e. doesn''t appear in the database ============================class Contact < ActiveRecord::Base before_create :generic_fields private def generic_fields created_by="test text" <=== DOESN''T SET IT self.created_by="test text" <=== DOESN''T SET IT @created_by="test text" <=== DOESN''T SET IT end end =============================> self.created_by= <== Not set (in database it''s not set either) Tks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg H
2006-Sep-10 09:27 UTC
Re: why doesn''t this work (setting attribute in "before_create")
bump (anyone able to point out why this doesn''t work below please - thanks) On 9/10/06, Greg Hauptmann <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi, > > Can anyone spot why the below doesn''t work? > > * I have a "created_by" column in my create table in the dB > * I have a "before_create" line, which definitely gets called > * I tried a few different ways to set the "created_by" attribute in the > model but it doesn''t seem to work, i.e. doesn''t appear in the database > ============================> class Contact < ActiveRecord::Base > before_create :generic_fields > private > def generic_fields > created_by="test text" <=== DOESN''T SET > IT > self.created_by="test text" <=== DOESN''T SET > IT > @created_by="test text" <=== DOESN''T SET > IT > end > end > ============================> => self.created_by= <== Not set (in database it''s not set either) > > Tks > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2006-Sep-10 11:12 UTC
Re: why doesn''t this work (setting attribute in "before_create")
solved it guys (just in case someone started to look at this) - "self.created_by = Suberb.current_user_gregs" as the syntax worked but noting - doh! My database column was a datetime not a string (prior to fixing this the column was showing NULL) I wonder whether rails should have really picked up on this error? The only way I was able to discover this was via code/db review. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Possibly Parallel Threads
- best way to add "created_by" entries to all tables???
- help me understand association attributes
- How to write manage created_on and created_by via mixin?
- does rails enforce referential integrity???
- before_create is after_validatation :on => :create , when it should be before_validation :on => :create