Rails: call another controller action from a controller

后端 未结 9 1067
眼角桃花
眼角桃花 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:17

    You can use url_for to get the URL for a controller and action and then use redirect_to to go to that URL.

    redirect_to url_for(:controller => :controller_name, :action => :action_name)
    

提交回复
热议问题