hi, i have 4 different controllers that are basically doing the same thing but just passing different parameters to the model functions. can i just place all the code in the application.rb file? so when an action comes in from a view, it goes to the controller, and then to the application.rb, and then passed to the model? -- 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 -~----------~----~----~----~------~----~------~--~---
Yes. ----- Original Message ----- From: "mixplate" <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> To: <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Sent: Monday, November 20, 2006 9:04 AM Subject: [Rails] question about putting code in application.rb...> > hi, i have 4 different controllers that are basically doing the same > thing but just passing different parameters to the model functions. can > i just place all the code in the application.rb file? > > so when an action comes in from a view, it goes to the controller, and > then to the application.rb, and then passed to the model? > > -- > 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 -~----------~----~----~----~------~----~------~--~---
mixplate wrote:> hi, i have 4 different controllers that are basically doing the same > thing but just passing different parameters to the model functions. can > i just place all the code in the application.rb file? > > so when an action comes in from a view, it goes to the controller, and > then to the application.rb, and then passed to the model?Not exactly. All controllers inherit from the class ApplicationController which resides your application.rb. So any action will be handled by your controller unless it doesn''t have that action defined. If your controller has no action, it will use any action from it''s parent''s class, in this case ApplicationController. It will never go to the model searching for methods, ever. In short, any functionality you want it all controller, put in application.rb. -- 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 -~----------~----~----~----~------~----~------~--~---
If you want this functionality in all controllers, then it should go in application.rb. If you want it in only some controllers but not others, you could create a new controller class AdminController< ApplicationController before_filter :admins_only end Then inherit from that instead class SomeOtherController < AdminController end You could also experiment with using modules to share code between controllers. On 11/20/06, Alex Wayne <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > mixplate wrote: > > hi, i have 4 different controllers that are basically doing the same > > thing but just passing different parameters to the model functions. can > > i just place all the code in the application.rb file? > > > > so when an action comes in from a view, it goes to the controller, and > > then to the application.rb, and then passed to the model? > > Not exactly. > > All controllers inherit from the class ApplicationController which > resides your application.rb. > > So any action will be handled by your controller unless it doesn''t have > that action defined. If your controller has no action, it will use any > action from it''s parent''s class, in this case ApplicationController. > > It will never go to the model searching for methods, ever. > > In short, any functionality you want it all controller, put in > application.rb. > > -- > 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 -~----------~----~----~----~------~----~------~--~---