问题
I m using Rails 3.2.1. how to use link_to with remote=>true
My Method in Controller
def clickme
@clk = "you click me"
respond_to do |format|
format.js { render :layout=>false }
end
end
My View
In my new.html.erb file
<%= link_to "click here", {:action=>"clickme"}, {:remote => true, :id=>"clk"} %>
<div id="allclick">
<%= render :partial => 'goclick' %>
</div>
_goclick.html.erb
<%= @clk %>
clickme.js.erb
$("allclick").update("<%= escape_javascript(render(:partial => "goclick")) %>");
On my web-page everything is fine when I click on click here link nothing change. But when I check Firebug console it shows me:
$("allclick").update("you click me");
In My application.js
//= require jquery
//= require jquery_ujs
Help Me :(
回答1:
try using html
instead of update
:
$("#allclick").html("<%= escape_javascript(render(:partial => "goclick")) %>");
回答2:
Use $("#allclick") not $("allclick"), you missed the "#" ;)
来源:https://stackoverflow.com/questions/9496172/how-to-use-link-to-with-ajax-in-rails-3-2-1