Hi all, I was wondering if it is possible to dynamically chain class methods in rails. Suppose there are several optional methods that a class may have, I want to chain call all the methods that apply to a certain class. Is it possible? What is the best approach to do achieve this? Thanks in advance. -- Anderson Mesquita www.aposasopa.com Linux User #419944 2009/8/12 doug <ddjolley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> > Let''s say that one has a set of controller actions that he plans to > deploy on a collection of different web sites. For the most part, any > particular action on any given web site in the collection is the same > as the corresponding action on any other web site in the collection. > However, there can be minor customizing tweaks to various actions on a > site by site basis. So, across web sites, corresponding controller > actions are similar but not identical. > > It would be nice to have the base (common) code for the actions in a > superclass of the controller. That way the base code could be kept > pristine and identical across all web sites. The minor customizing > tweaks could be implemented as overriding code in the controller. > That makes the tweaks much more prominent. In addition, the big > advantage is that if the base code is updated and the updates don''t > affect the tweaks, updates to the base code are simply drop-in > replacements which don''t require any customization. > > The base code could be put in the application controller; but, then it > would inherit down to all controllers. A separate class for each > controller inserted between the application controller and the > particular controller involved is what seems to be needed. My > question is: Is that the way to do it; or, is there a better way? > I''m concerned about breaking the class chain setup by Rails. Maybe > it''s no big deal; but, I''d like to know that for sure. > > Thanks for any input. > > ... doug > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 Sep 1, 11:23 am, Anderson Mesquita <anderson...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I was wondering if it is possible to dynamically chain class methods in > rails. Suppose there are several optional methods that a class may have, I > want to chain call all the methods that apply to a certain class. Is it > possible? What is the best approach to do achieve this? >ActiveSupport::Callbacks ? Fred> Thanks in advance. > > -- > Anderson Mesquitawww.aposasopa.com > Linux User #419944 > > 2009/8/12 doug <ddjol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > > > > Let''s say that one has a set of controller actions that he plans to > > deploy on a collection of different web sites. For the most part, any > > particular action on any given web site in the collection is the same > > as the corresponding action on any other web site in the collection. > > However, there can be minor customizing tweaks to various actions on a > > site by site basis. So, across web sites, corresponding controller > > actions are similar but not identical. > > > It would be nice to have the base (common) code for the actions in a > > superclass of the controller. That way the base code could be kept > > pristine and identical across all web sites. The minor customizing > > tweaks could be implemented as overriding code in the controller. > > That makes the tweaks much more prominent. In addition, the big > > advantage is that if the base code is updated and the updates don''t > > affect the tweaks, updates to the base code are simply drop-in > > replacements which don''t require any customization. > > > The base code could be put in the application controller; but, then it > > would inherit down to all controllers. A separate class for each > > controller inserted between the application controller and the > > particular controller involved is what seems to be needed. My > > question is: Is that the way to do it; or, is there a better way? > > I''m concerned about breaking the class chain setup by Rails. Maybe > > it''s no big deal; but, I''d like to know that for sure. > > > Thanks for any input. > > > ... doug
On Tue, Sep 1, 2009 at 6:23 AM, Anderson Mesquita<andersonvom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I was wondering if it is possible to dynamically chain class methods in > rails. Suppose there are several optional methods that a class may have, I > want to chain call all the methods that apply to a certain class. Is it > possible? What is the best approach to do achieve this?ActiveSupport defined Module#alias_method_chain which is used extensively to do what I think you are asking for. Googling alias_method_chain should fill you in on the details. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale