I was previously doing the following in javascript:
$('<img>')
.attr('class', 'logo')
.attr('src', '/images/logos/all/logo_one_beta.png')
.appendTo('#container');
Now that I’m porting to rails I’ve been using embedded ruby in html and the image_tag rails helper such as
<%= image_tag "logos/all/logo_one_beta.png", :class => "logo" %>
with logo_one_beta.png located at app/assets/images/logos/all/
The embedded ruby in html works fine but I want to add it to the html via javascript using the jquery appendTo method as I was previously doing.
I tried the following and it is not working:
$('<%= image_tag "logos/all/logo_one_beta.png", :class => "logo" %>').appendTo('#container');
I also tried
$("#container").append('<%= image_tag "logos/all/logo_one_beta.png", :class => "logo" %>')
I don’t receive any error, the image simply doesn’t show up.
where’s that code? on a .js file? or in a .js.erb view? you can’t use ruby code inside a simple js file
use the debugger of your favourite browser to see what’s happening there
I don’t think you need to port that to rails anyway