please help -- Posted via http://www.ruby-forum.com/.
Abhinav Saxena
2009-Sep-09 09:15 UTC
Re: how to implement get and set method in ruby on rails
Simplest one: attr_accessor :variable_name # this will generate get and set method for you If you meant how to write get & set methods for database table column in your model: def column_name read_attribute(:column_name) # if column_name is the name of the column end def column_name=(value) write_attribute(:column_name, value) # or you can modify value, and call super with it. Search on Internet to find more. end Thanks, Abhinav -- अभिनव http://twitter.com/abhinav On Wed, Sep 9, 2009 at 2:33 PM, Venkat Eee <rails-mailing-list-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt> wrote:> > please help > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Sep-09 12:16 UTC
Re: how to implement get and set method in ruby on rails
On Sep 9, 10:15 am, Abhinav Saxena <abhinav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Simplest one: > attr_accessor :variable_name # this will generate get and set method for > you >But don''t do this for database backed attributes - for those the accessor methods are added for you. Fred> If you meant how to write get & set methods for database table column in > your model: > > def column_name > read_attribute(:column_name) # if column_name is the name of the column > end > > def column_name=(value) > write_attribute(:column_name, value) # or you can modify value, and > call super with it. Search on Internet to find more. > end > > Thanks, > Abhinav > -- > अभिनवhttp://twitter.com/abhinav > > On Wed, Sep 9, 2009 at 2:33 PM, Venkat Eee <rails-mailing-l...@andreas-s.net > > > > > wrote: > > > please help > > -- > > Posted viahttp://www.ruby-forum.com/.