Two of my controllers need access to same method. I instantly put them in ApplicationController and the problem was solved. Now I''m thinking my ApplicationController is getting polluted because there are many cases in which a method is needed by two or three controllers. What are the other ways to handle such cases. One case could be to have a base controller and then to extend these controllers so that they get the common methods. Well I don''t like it that much. Any thoughts. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You could have a module with the common methods and include it in controllers needing those methods Fred -- 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 -~----------~----~----~----~------~----~------~--~---
Raj Singh wrote:> Two of my controllers need access to same method. I instantly put them > in > ApplicationController and the problem was solved. > > Now I''m thinking my ApplicationController is getting polluted because > there > are many cases in which a method is needed by two or three controllers. > What > are the other ways to handle such cases. > > One case could be to have a base controller and then to extend these > controllers so that they get the common methods. Well I don''t like it > that > much. > > Any thoughts.Group the methods into categories. Put each category in a file in #{RAILS_ROOT}/lib/aplication_controller (or where ever). Easy (but less orginized) way. In each file put: AplicationController <ActionController::Base #function go here end and require the files in Application.rb More complex (but Ruby like ) way. Each file defines a module with the functions. Include the module in either ApplicationController or individual Controllers. JFM -- 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 -~----------~----~----~----~------~----~------~--~---