Felix
Felix

Reputation: 5619

Rails calling a action with jquery?

I have a Rails application were I want to introduce some jquery code.

I have button

<button type="button" id="savesettings" class="btn btn-primary">Save changes</button>

Now I want when I press this button

$("#savesettings").click(function(){

                        })

A controller action should be called. like this:

<%=url_for(:action => :first, :id => @xyz.id, :mail => @xyz.hash_for_url)%>

How can I do this?

Upvotes: 0

Views: 43

Answers (1)

bunty
bunty

Reputation: 1088

you can directly write link_to instead of button as,

<%= link_to "Save Changes", url_for(:action => :first, :id => @xyz.id, :mail => @xyz.hash_for_url), remote:true, class:"btn btn-primary" %>

remote:true will serve you request as js

Upvotes: 1

Related Questions