简体   繁体   中英

How do I forward an action to another controller in Rails?

Rails 4 - I have an action that handles routes like www.site.com/catalog/shoes/sport/ABC123 for product and www.site.com/catalog/shoes/sport for category The problem is I have to display some seo-paid links (not my choise, I just have to) in format www.site.com/href , and that link must me handled as some product category. That's not the only case - in future, there might be some other "short"-links, that are pointing to other parts of my site

When I used Symfony, I could just write $this->forward('controller', 'action') and get another controller's output while saving short route, but in Rails I see only redirect_to, and it does not preserve short url?

Assuming I have a route get ':href' => 'index#simple', as: :simple , how do I forward execution to another controller (or just call controller's method?), preserving original route? - In "rails way", of course

Thank you

您可以仅在控制器操作中使用'redirect_to controller_action_path'/ redirect_to'/ controller / action'。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM