Rails:从控制器调用另一个控制器动作

Rails:从控制器调用另一个控制器动作

问题描述:

我需要从控制器 B 调用控制器 A 中的创建操作.

I need to call the create action in controller A, from controller B.

原因是当我从控制器 B 调用时需要不同的重定向.

The reason is that I need to redirect differently when I'm calling from controller B.

可以在 Rails 中完成吗?

Can it be done in Rails?

您可以使用重定向到该操作:

You can use a redirect to that action :

redirect_to your_controller_action_url

更多信息:Rails 指南

只渲染新动作:

redirect_to your_controller_action_url and return