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

后端 未结 4 701
一整个雨季
一整个雨季 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:26

    I like Pan's solution but I prefer to use the ID of the form directly which you can get from the dom_id(obj). The form_for helper also uses dom_id(obj) to assign the form's ID. This way you aren't dependent on setting classes by hand or subject to accidentally submitting more than one form that share the same CSS class. It looks a little stranger but I usually have a custom FormBuilder anyway so I just add a generic link_to_submit method to encapsulate this:

    <%= link_to 'Save', "#", :onclick => "$('##{dom_id(@user)}').submit()" %>
    

提交回复
热议问题