开发者

Rails 2.3.x: Call other controller from within a controller

开发者 https://www.devze.com 2023-03-05 08:31 出处:网络
Is it somehow possible to call another controller\'s action from within a controller? redirect_to is not what I need, because I\'ve stored the request information (path, params, referer, xhr, ...) of

Is it somehow possible to call another controller's action from within a controller? redirect_to is not what I need, because I've stored the request information (path, params, referer, xhr, ...) of another request and want to execute it now. Basically an exec for controller actions would be wha开发者_如何转开发t I need. Simply instantiating the controller, setting the needed instance variables and calling the action is not enough, because this does not invoke the right filters and error handlers.


No. You can't do this. This is why with the MVC pattern you hear people recommend "skinny controllers".

Move the logic down into the models as much as possible. Then it's easy to share across controllers. Or you can try moving the similar actions into a shared controller so that they can share behaviour.

0

精彩评论

暂无评论...
验证码 换一张
取 消