[英]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. Rails 4-我有一个动作可以处理产品路线,例如
www.site.com/catalog/shoes/sport/ABC123
和类别的www.site.com/catalog/shoes/sport
问题是我必须显示一些seo-付费链接(不是我的选择,我只需www.site.com/href
),格式为www.site.com/href
,并且该链接必须作为某种产品类别处理。 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? 当我使用Symfony时,我可以编写
$this->forward('controller', 'action')
并在保存短路径的同时获取另一个控制器的输出,但是在Rails中,我只能看到redirect_to,并且它不保留短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? 假设我有一条路线,
get ':href' => 'index#simple', as: :simple
,如何将执行转发到另一个控制器(或只是调用控制器的方法?),并保留原始路线? - In "rails way", of course -当然是“铁轨方式”
Thank you 谢谢
您可以仅在控制器操作中使用'redirect_to controller_action_path'/ redirect_to'/ controller / action'。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.