Rails: call another controller action from a controller

后端 未结 9 1068
眼角桃花
眼角桃花 2020-11-27 11:47

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

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

9条回答
  •  不知归路
    2020-11-27 12:04

    To use one controller from another, do this:

    def action_that_calls_one_from_another_controller
      controller_you_want = ControllerYouWant.new
      controller_you_want.request = request
      controller_you_want.response = response
      controller_you_want.action_you_want
    end
    

提交回复
热议问题