In one of my projects I came across a situation where I needed to submit a form with a link. By default, a form is submitted either using a submit_tag or button_to helpers in ruby on rails. In this case it had to be submitted through a link. For this, I searched and found a way to do it:
<%= link_to_remote 'Submit',
:url=>{:controller=>'c_name', :action=>'a_name', :id=>'some_id'},
:with=>"Form.Element.serialize('form_id')"
%>
Alternatively, you can also use the following helper:
<%= link_to_function 'Submit',
remote_function(:url=>{:controller=>'c_name',
:action=>'a_name',
:id=>'some_id'},
:method=>:post,
:with=>"Form.serialize('form_id')")
%>
The form can be passed using the optional paramter :with.
No comments:
Post a Comment