Daniel Smedegaard Buus
2007-Mar-08 10:11 UTC
Extending controllers with actions from external files?
Hey :) I have some auto_complete_for_blah_blah actions that are used in different controllers. In the spirit of DRY, I''d like to separate these actions in unique files which I then load into the controllers that use them. Okay, so the way I can do it now is for instance myapp +- lib +- auto_complete_for +- user_printed_name.rb And then, I can require ''auto_complete_for/user_printed_name'' in the controllers that use this auto_completer. However, even though the method is available to the controller, I still get "no action responded to ''auto_complete_for_user_printed_name''" when I call the action. That is, it''s available as a local method to the controller, but I''d really like for it to appear as an action, so that I don''t have to create a proxy, like, def auto_complete_for_user_printed_name shared_auto_complete_for_user_printed_name end How would I do that? Thanks :) Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Lionel Bouton
2007-Mar-08 10:50 UTC
Re: Extending controllers with actions from external files?
Daniel Smedegaard Buus wrote the following on 08.03.2007 11:11 :> Hey :) > > I have some auto_complete_for_blah_blah actions that are used in > different controllers. In the spirit of DRY, I''d like to separate > these actions in unique files which I then load into the controllers > that use them. > > Okay, so the way I can do it now is for instance > myapp > +- lib > +- auto_complete_for > +- user_printed_name.rb > > And then, I can > require ''auto_complete_for/user_printed_name'' > > in the controllers that use this auto_completer. >From memory, you should: include AutoCompleteFor::UserPrintedName assuming this the module name defined in lib/auto_complete_for/user_printed_name.rb You probably don''t need the require if your module naming matches your directory structure like in the example above (Rails figures the needed require for itself). Lionel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Daniel Smedegaard Buus
2007-Mar-08 11:18 UTC
Re: Extending controllers with actions from external files?
On Mar 8, 11:50 am, Lionel Bouton <lionel-subscript...-WTamNBQcZIx7tPAFqOLdPg@public.gmane.org> wrote:> > From memory, you should: > include AutoCompleteFor::UserPrintedName > > assuming this the module name defined in > lib/auto_complete_for/user_printed_name.rb > > You probably don''t need the require if your module naming matches your > directory structure like in the example above (Rails figures the needed > require for itself). >Close! Following your advice and a little fiddling, I found that with, lib/auto_complete_for.rb: module AutoCompleteFor module UserPrintedName def auto_complete_for_user_printed_name // implementation end end end I can use the syntax you describe, include AutoCompleteFor::UserPrintedName and have the actions implemented! Thank you very much! :D Daniel :)> Lionel--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---