Is this possible? I don''t want to redirect, just want to utilize a method for convenience sake. I have a messages controller that just creates messages from user to user and there are many different kinds of messages, each generated from a different controller/view. Is it possible to call another controller''s method inside a controller? If not, is there another best practice to do this? I don''t want to put the functionality in the model because it cannot access helper methods, and I use current_user from restful_authentication. Thanks for any help, Dino --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Felipe Vergara
2008-Sep-03 13:13 UTC
Re: Can I call another controllers method from a controller?
yes it is posible, if you want to use a method from the helper you have to add the helper to your controller include NameofthecontrollerHelper the to access methods from the controller of the helper you need to call self.nameofthemethod also if you want to access more than the CRUD (create,remove,update,delete) methods from the browser (common path ej new_controller_path) then yo have to add the methods to the routes: map.resources :nameofthecontroller, :collection=>{:nameofthemethod => :any} #you can chanche the any for a specific action hope it helps On Wed, Sep 3, 2008 at 6:58 AM, dino d. <dinodorroco-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > Is this possible? I don''t want to redirect, just want to utilize a > method for convenience sake. I have a messages controller that just > creates messages from user to user and there are many different kinds > of messages, each generated from a different controller/view. Is it > possible to call another controller''s method inside a controller? If > not, is there another best practice to do this? I don''t want to put > the functionality in the model because it cannot access helper > methods, and I use current_user from restful_authentication. > > Thanks for any help, > Dino > > >-- Felipe Vergara Contesse Ingeniería Civil Industrial UC --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2008-Sep-04 00:04 UTC
Re: Can I call another controllers method from a controller?
dino d. wrote:> Is this possible? I don''t want to redirect, just want to utilize a > method for convenience sake. I have a messages controller that just > creates messages from user to user and there are many different kinds > of messages, each generated from a different controller/view. Is it > possible to call another controller''s method inside a controller? If > not, is there another best practice to do this? I don''t want to put > the functionality in the model because it cannot access helper > methods, and I use current_user from restful_authentication.If you move the method you wish to call into a controller that is a parent of both controllers, you can just call that method from the requested method. Add a render(:template) call to the destination method to ensure that the right view is rendered. -- Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.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 -~----------~----~----~----~------~----~------~--~---
Brendon
2008-Sep-04 01:39 UTC
Re: Can I call another controllers method from a controller?
Hi had this same problem to deal with, and I ended up having to copy the functionality into another set of controllers because they were logically too far from each other (they already had their own important inheritances). I never really dealt with it, but I will have to face up to it again soon as we''re modifying that part of the application. I''ve been toying with the idea of putting a lot of the duplicated functionality into a module in the lib directory and including that? Would be great to hear anyone''s war stories :) Cheers, Brendon On Sep 4, 12:04 pm, Mark Reginald James <m...-ejQy8aU/RJumpXlQD71PVDSf8X3wrgjD@public.gmane.org> wrote:> dino d. wrote: > > Is this possible? I don''t want to redirect, just want to utilize a > > method for convenience sake. I have a messages controller that just > > creates messages from user to user and there are many different kinds > > of messages, each generated from a different controller/view. Is it > > possible to call another controller''s method inside a controller? If > > not, is there another best practice to do this? I don''t want to put > > the functionality in the model because it cannot access helper > > methods, and I use current_user from restful_authentication. > > If you move the method you wish to call into a controller that > is a parent of both controllers, you can just call that method > from the requested method. Add a render(:template) call to > the destination method to ensure that the right view is rendered. > > -- > Rails Wheels - Find Plugins, List & Sell Plugins -http://railswheels.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---