Ok I have this problem I’m trying to use Jquery to load a partial in replace of a listed object.
index.html.erb
<div class="style_image_<%= style.id %>" > <%=link_to image_tag(style.cover.pic.url(:small)), style %></div>
loadshow:
$(function() {
$(".style_image_<%= style.id %> a").click(function() {
$(".style_image_<%= style.id %>").html("loading... ")
$(".style_image_<%= style.id %>").html("<%= escape_javascript(render("show")) %>")
$.get(this.href, null, null, "html");
return false;
});
});
_show.html.erb:
<%=link_to image_tag(style.cover.pic.url(:normal)), style %>
I’m getting this error:
missing ) after argument list
[Break on this error] $(".style_image_<%= style.id %>").htm...scape_javascript(render("show")) %>")\n
There is two problems with my code here the first is the click function is not targeting the .style_image_<%= style.id %> …. i.e (.style_image_42) if I replace the css target with 42 instead of _style.id the click target works; why is this?
And with or without this change the _show partial is not render and the above error is given.
Not really that good with Javascript any help would be great!
P.s.
The effect I really want is like one of those super cool cargo themes: http://cargocollective.com/publikspace
Thanks Dan!
alt text http://s3.amazonaws.com/data.tumblr.com/tumblr_kzu1cnOUUs1qbto6oo1_1280.png?AWSAccessKeyId=0RYTHV9YYQ4W5Q3HQMG2&Expires=1269597925&Signature=XuwwBhKKCKu3FWGpmqXmBqwxzS0%3D
Still not sure why my js.erb file don’t understand <%=style.id%>, maybe it’s not the done thing to do here.
I have two solutions for this problem:
write the javascript in the controller and use a link_to_remote.
Unobtrusively Load link path in to the DIV of the link:
Image_tag link as above!
and in my Application.js file
With this method if javascript is off link will tak you to the show path of the object.
Thanks goes out to Nick Craver for give me the heads up on this!