简体   繁体   English

如何将动作转发到Rails中的另一个控制器?

[英]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.

相关问题 如何创建另一个控制器动作以在Rails中创建对象? - How do I create another controller action to create an object in rails? 在Ruby on Rails中,如何将控制权传递给另一个控制器中的操作? - In Ruby on Rails, how do I pass control to an action in another controller? Rails - 如何避免必须从另一个控制器中的create action触发一个控制器中的create操作 - Rails - how do I avoid having to trigger the create action in one controller from the create action in another controller 如何创建Rails控制器动作? - How do I create a rails controller action? Rails - 如何将变量从一个控制器动作移动到另一个控制器动作而不重置它 - Rails - how do I move a variable from one controller action to another without resetting it 如何从Rails 3中的另一个动作中调用更新动作? - How do I call update action from another action in rails 3? 在Rails中,如何验证特定控制器动作的模型? - In Rails, how do I validate a model for a specific controller action? 如何路由到新的rails控制器操作 - How do I route to a new rails controller action Rails:我如何在控制器/动作上使用javascript条件 - Rails: how do I use javascript conditional on controller/action 如何在Rails 3的另一个控制器中重定向到特定操作? - How do I redirect to a specific action in a different controller in Rails 3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM