form_for but to post to a different action

form_for but to post to a different action

Asked on January 12, 2019 in Ruby on Rails.
Add Comment


  • 3 Answer(s)

    Follow this command:

    form_for @user, :url => url_for(:controller => 'mycontroller', :action => 'myaction')
    

    or,

    form_for @user, :url => whatever_path
    

     

    Answered on January 12, 2019.
    Add Comment

    Alternative solution form_for :

    form_for @user, :url => {:action => "YourActionName"}
    

    Answered on January 12, 2019.
    Add Comment

    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| -%>

     

    Answered on January 13, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.