Philip Hallstrom
2006-Nov-28 00:53 UTC
Common actions "split" amoung several controllers? how to?
Hi all - I''ve got a set of common actions (for displaying photo thumbnails and their preview) that I''d like to share b/n a couple of controllers (ie. photos for people and photos for events). I''m trying to figure out how best to extract this common functionality so it''s easy to update/manage (ie. dry). The views aren''t a problem, I know how to do that, but I''m getting stuck with the controller/actions... Right now I''ve got my actions in a *module* that I''m *include*''ing in each controller. Works except I get the following when one of the protected methods (defined in the module) tries to use Paginator. It works if I move it into the controller. My module is in lib/photos.rb and the error I''m getting is this: uninitialized constant Paginator This error occured while loading the following files: photos/paginator.rb Also, I''d like to setup a before_filter for these common actions, but that doesn''t seem to work very well either. Any ideas? Or other solutions? Thanks! -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
phallstrom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Nov-28 00:59 UTC
Re: Common actions "split" amoung several controllers? how to?
(skip down) On Nov 27, 4:53 pm, Philip Hallstrom <r...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> Hi all - > > I''ve got a set of common actions (for displaying photo thumbnails and > their preview) that I''d like to share b/n a couple of controllers (ie. > photos for people and photos for events). > > I''m trying to figure out how best to extract this common functionality so > it''s easy to update/manage (ie. dry). > > The views aren''t a problem, I know how to do that, but I''m getting stuck > with the controller/actions... > > Right now I''ve got my actions in a *module* that I''m *include*''ing in each > controller. Works except I get the following when one of the protected > methods (defined in the module) tries to use Paginator. It works if I > move it into the controller. > > My module is in lib/photos.rb and the error I''m getting is this: > > uninitialized constant Paginator > This error occured while loading the following files: > photos/paginator.rbWell, this is fixed by explicitly calling ActionController::Pagination::Paginator instead of just Paginator... Still curious about best practices though....> > Also, I''d like to setup a before_filter for these common actions, but that > doesn''t seem to work very well either. > > Any ideas? Or other solutions? > > Thanks! > > -philip--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Nov-28 01:36 UTC
Re: Common actions "split" amoung several controllers? how to?
Hi -- On Mon, 27 Nov 2006, Philip Hallstrom wrote:> > Hi all - > > I''ve got a set of common actions (for displaying photo thumbnails and > their preview) that I''d like to share b/n a couple of controllers (ie. > photos for people and photos for events). > > I''m trying to figure out how best to extract this common functionality so > it''s easy to update/manage (ie. dry). > > The views aren''t a problem, I know how to do that, but I''m getting stuck > with the controller/actions... > > Right now I''ve got my actions in a *module* that I''m *include*''ing in each > controller. Works except I get the following when one of the protected > methods (defined in the module) tries to use Paginator. It works if I > move it into the controller. > > My module is in lib/photos.rb and the error I''m getting is this: > > uninitialized constant Paginator > This error occured while loading the following files: > photos/paginator.rb > > > Also, I''d like to setup a before_filter for these common actions, but that > doesn''t seem to work very well either. > > Any ideas? Or other solutions?What about putting them in application.rb? That way, they''ll be in the parent class of the controller classes. David -- David A. Black | dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB''s Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Brian Hogan
2006-Nov-28 03:11 UTC
Re: Common actions "split" amoung several controllers? how to?
Another option is to make your own parent class (like application.rb) and have your common controllers inherit from that. You could also play around with mixing the actions in via a module. In theory that should work but I''ve not done it. On 11/27/06, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org <dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote:> > > Hi -- > > On Mon, 27 Nov 2006, Philip Hallstrom wrote: > > > > > Hi all - > > > > I''ve got a set of common actions (for displaying photo thumbnails and > > their preview) that I''d like to share b/n a couple of controllers (ie. > > photos for people and photos for events). > > > > I''m trying to figure out how best to extract this common functionality > so > > it''s easy to update/manage (ie. dry). > > > > The views aren''t a problem, I know how to do that, but I''m getting stuck > > with the controller/actions... > > > > Right now I''ve got my actions in a *module* that I''m *include*''ing in > each > > controller. Works except I get the following when one of the protected > > methods (defined in the module) tries to use Paginator. It works if I > > move it into the controller. > > > > My module is in lib/photos.rb and the error I''m getting is this: > > > > uninitialized constant Paginator > > This error occured while loading the following files: > > photos/paginator.rb > > > > > > Also, I''d like to setup a before_filter for these common actions, but > that > > doesn''t seem to work very well either. > > > > Any ideas? Or other solutions? > > What about putting them in application.rb? That way, they''ll be in > the parent class of the controller classes. > > > David > > -- > David A. Black | dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org > Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] > DABlog (DAB''s Weblog) [2] | Co-director, Ruby Central, Inc. [4] > [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com > [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2006-Nov-28 03:23 UTC
Re: Common actions "split" amoung several controllers? how to?
>> I''ve got a set of common actions (for displaying photo thumbnails and >> their preview) that I''d like to share b/n a couple of controllers (ie. >> photos for people and photos for events). >> >> I''m trying to figure out how best to extract this common functionality so >> it''s easy to update/manage (ie. dry). >> >> The views aren''t a problem, I know how to do that, but I''m getting stuck >> with the controller/actions... >> >> Right now I''ve got my actions in a *module* that I''m *include*''ing in each >> controller. Works except I get the following when one of the protected >> methods (defined in the module) tries to use Paginator. It works if I >> move it into the controller. >> >> My module is in lib/photos.rb and the error I''m getting is this: >> >> uninitialized constant Paginator >> This error occured while loading the following files: >> photos/paginator.rb >> >> >> Also, I''d like to setup a before_filter for these common actions, but that >> doesn''t seem to work very well either. >> >> Any ideas? Or other solutions? > > What about putting them in application.rb? That way, they''ll be in > the parent class of the controller classes.Hrm... good idea, but I think our app is too big to justify this... however, I could create another controller and have these controllers inherit from it... hrm... tempting :) Thanks! -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---