Hi I have the models 1.ServiceDeskTicket with fields id --- number --- service_desk_status_id -- created_on -- updated_on etc 2.ServiceDeskActivity with fields id -- service_desk_ticket_id -- description -- created_on -- updated_on 3.ServiceDeskAttachment id -- service_desk_ticket_id -- attachment -- created_on -- updated_on Relations as ServiceDeskticket has_many service_desk_activities ServiceDeskticket has_many service_desk_attachments ServiceDeskActivity belongs service_desk_ticket ServiceDeskAttachment belongs_to service_desk_ticket Now my requiremnet is whenever a new service desk activity as well as service desk attachment is added the updated_on field of ServiceDeskTicket is to be updated..(created_on and updated_on magic fields of rails)..Can I set this in ServiceDeskTicket class like a call_back..Since I am very new to rails call back functionality asking like this..Please correct if wrong...How can I do this without rewritng the code(I ma not asking update_attribute)..If I continue like sd_ticket.update_attribute(''fieldname'',value) i have to do in all the definitions .How can I avoid this Thanks in advance Sijo -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Sijo Kg wrote:> > Now my requiremnet is whenever a new service desk activity as > well as service desk attachment is added the updated_on field of > ServiceDeskTicket is to be updated..(created_on and updated_on magic > fields of rails)..Can I set this in ServiceDeskTicket class like a > call_back..Since I am very new to rails call back functionality asking > like this..Please correct if wrong...How can I do this without rewritng > the code(I ma not asking update_attribute)..If I continue like > sd_ticket.update_attribute(''fieldname'',value) i have to do in all the > definitions .How can I avoid this > > Thanks in advance > SijoYour callbacks should go in the class that triggers the actions when it is saved. eg #in service_desk_activity.rb before_save :update_ticket def update_ticket self.service_desk_ticket.save end because you''re using the magic timestamps, just saving the associated ticket object should update updated_at correctly. You can use the same code in the ''attachment'' class as well i think. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Thanks for your reply. Sijo -- 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?hl=en -~----------~----~----~----~------~----~------~--~---