form_for but to post to a different action

后端 未结 6 2312
小蘑菇
小蘑菇 2020-12-02 05:08

I want to have a form_for @user, but post to a custom action in the users controller.

How can I do this?

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-02 05:51

    If you want to pass custom Controller to a form_for while rendering a partial form you can use this:

    <%= render 'form', :locals => {:controller => 'my_controller', :action => 'my_action'}%>
    

    and then in the form partial use this local variable like this:

    <%= form_for(:post, :url => url_for(:controller => locals[:controller], :action => locals[:action]), html: {class: ""} ) do |f| -%>
    

提交回复
热议问题