Can I call another controllers method from a controller?

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

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. [email protected] wrote:

Thanks for any help,
Dino


Felipe V. Contesse
Ingeniería Civil Industrial UC

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

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 :slight_smile:

Cheers,

Brendon

On Sep 4, 12:04 pm, Mark Reginald J. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs