Rails, how do you submit a form with a text link?

后端 未结 4 702
一整个雨季
一整个雨季 2021-02-09 14:49

I am trying to get this form to submit correctly. Here\'s what I have so far:

<% form_for(:user, :url => update_user_setting_path, :remote => true, :htm         


        
4条回答
  •  别跟我提以往
    2021-02-09 15:22

    No, you are not using link_to properly. You need to use a submit tag to submit your form, not a link_to tag, for example:

    <% form_for(:user, :url => update_user_setting_path, :remote => true, :html => {:method => :post, :class => "search_form general_form"}) do |f| %>
      ...
      
  • <%= f.submit "Save" %>
  • If you want to use a text link you'll have to have javascript submit the form. For example, if you are using jQuery you could do the following:

    <%= link_to 'Save', "#", :onclick=>"$('.search_form').submit()" %>
    

提交回复
热议问题