Hi, I got i.e. Ticket and TicketChange models and would like to create TicketChange object whenever Ticket object is updated. Currently I''m creating new TicketChange in Ticket#after_update callback and simply serialize slightly modified ticket.changes hash. Ticket can be updated using 2 ways - using in-place-editors (ajax) and a form. The problem is with updating through the form - I''d like users to be able to comment the change and upload files for each change (I''m using attachment_fu). The form is passing parameters to TicketController#update action, the ticket is updated and automagically ticket change is created as well. But how to pass the comment and file to it? Any tips how to solve it? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Craig Demyanovich
2008-Oct-23 13:17 UTC
Re: How to pass parameters to after_update callback?
Since the after_update is declared in your Ticket model, you should be able to access the params hash from the method. For example class Ticket < ActiveRecord::Base ... after_update :record_changes ... private ... def record_changes TicketChange.create!(params[:comment], params[:filename], ...) ... end end Regards, Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Unless you provide the parameters to the model, any callbacks will be unable to see them. (assuming that you''re talking about the parameters from a form post?) On Thu, Oct 23, 2008 at 5:23 AM, szimek <szimek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > I got i.e. Ticket and TicketChange models and would like to create > TicketChange object whenever Ticket object is updated. > > Currently I''m creating new TicketChange in Ticket#after_update > callback and simply serialize slightly modified ticket.changes hash. > Ticket can be updated using 2 ways - using in-place-editors (ajax) and > a form. > > The problem is with updating through the form - I''d like users to be > able to comment the change and upload files for each change (I''m using > attachment_fu). The form is passing parameters to > TicketController#update action, the ticket is updated and > automagically ticket change is created as well. But how to pass the > comment and file to it? > > Any tips how to solve it? > > >-- Robby Russell Chief Evangelist, Partner PLANET ARGON, LLC design // development // hosting http://www.planetargon.com/ http://www.robbyonrails.com/ aim: planetargon +1 503 445 2457 +1 877 55 ARGON [toll free] +1 815 642 4068 [fax] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Craig Demyanovich
2008-Oct-23 16:23 UTC
Re: How to pass parameters to after_update callback?
D''oh. I should more carefully reply to posts after just waking up. I don''t know how I mixed controllers and models this morning. Time to enjoy the MVC public service announcements <http://www.railsenvy.com/tags/MVC> again. Sorry for the confusion everyone. Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Andrius Chamentauskas
2008-Oct-24 13:49 UTC
Re: How to pass parameters to after_update callback?
How about making two read-write attributes, one for changes and one for files, in Ticket model. They would be automatically assigned from params hash (yes you can assign any attribute using params hash, not only database related fields) and you could use them in after update method. On Oct 23, 3:23 pm, szimek <szi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I got i.e. Ticket and TicketChange models and would like to create > TicketChange object whenever Ticket object is updated. > > Currently I''m creating new TicketChange in Ticket#after_update > callback and simply serialize slightly modified ticket.changes hash. > Ticket can be updated using 2 ways - using in-place-editors (ajax) and > a form. > > The problem is with updating through the form - I''d like users to be > able to comment the change and upload files for each change (I''m using > attachment_fu). The form is passing parameters to > TicketController#update action, the ticket is updated and > automagically ticket change is created as well. But how to pass the > comment and file to it? > > Any tips how to solve it?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---