What's the correct way to run one controller action from another controller action without an HTTP redirect?

后端 未结 6 594
无人及你
无人及你 2020-12-30 09:33

I\'d like to be able to dispatch from one controller action to another conditionally, based on a combination of query parameters and data in the database.

What I hav

6条回答
  •  天涯浪人
    2020-12-30 09:44

    Create an instance of the controller class:

    @my_other_controller = MyOtherController.new
    

    Then call methods on it:

    @my_other_controller.some_method(params[:id])
    

    I prefer the module idea, but this should do the trick.

    You can also pass parameters as a whole from another controller:

    @my_other_controller.params = params
    

提交回复
热议问题