how to use link_to with :remote=>true in rails 3.2.1

658 views
Skip to first unread message

Manish Nautiyal

unread,
Feb 29, 2012, 4:07:20 AM2/29/12
to rubyonra...@googlegroups.com
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");

--------------------------------------------
Help Me :(

--
Posted via http://www.ruby-forum.com/.

Tim Shaffer

unread,
Feb 29, 2012, 8:13:13 AM2/29/12
to rubyonra...@googlegroups.com
You probably want to use $("#allclick").update instead of $("allclick").update

Note the # that indicates you are selecting an element by the ID.

Manish Nautiyal

unread,
Feb 29, 2012, 8:18:09 AM2/29/12
to rubyonra...@googlegroups.com
Tim Shaffer wrote in post #1049440:

> You probably want to use $("#allclick").update instead of
> $("allclick").update
>
> Note the # that indicates you are selecting an element by the ID.

I'm using $("#allclick").update

Manish Nautiyal

unread,
Mar 1, 2012, 2:09:40 AM3/1/12
to rubyonra...@googlegroups.com
after doing some googling I got the answer

wrong way :
$("#allclick").update("<%= escape_javascript(render(:partial =>
"goclick")) %>");

====================================================================
correct way :
$("#allclick").html("<%= escape_javascript(render(:partial =>
"goclick")) %>");

====================================================================
Instead of update now I'm using html

Walter Lee Davis

unread,
Mar 1, 2012, 8:38:12 AM3/1/12
to rubyonra...@googlegroups.com

Update would work perfectly if you were using Prototype.js instead of jQuery.

Walter

Reply all
Reply to author
Forward
0 new messages