Calling Rails action from Javascript -
i have link_to
in calls update
action in controller:
<%= link_to((image_tag("lock_closed.svg", :class => "edit")), :controller => "sections", :action => "update",:id => section.id, :remote => true) %>
but call update
action through javascript ordinary image tag.
so like:
<%= image_tag("lock_closed.svg", :class => "edit")%>
and:
$(".edit").click(function(){ if ($(this).hasclass("update")){ // call update action } else { //do else }; })
is possible call action way? i've been finding bit on using get
& post
or ajax
methods i'm not sure how utilise them target specific controller & action.
send ajax call
$(".edit").click(function(){ if ($(this).hasclass("update")){ $.ajax({ type: "put", url: "/sections/<%= section.id %>" }); } else { //do else }; })
Comments
Post a Comment