Reputation: 11683
I'm fairly new to Rails. The code snippet in Figure 1 is causing a rails exception wrong number of arguments (0 for 1) when the variable asset_path
is added in front of the value of original
.
Figure 1: Rails image_tag
<%= image_tag("foo/blank.gif", {
:class =>"lazy",
:data => { "original" => asset_path + 'foo/image-01.png'},
:alt => ""}) %>
The problem seems to lie with the way the two strings are joined:
asset_path + 'foo/image-01.png'
What is the correct way of joining two strings in this context?
Upvotes: 0
Views: 112
Reputation: 95
In addition, you should use "asset_path" in your assets (javascript, css), for example:
$('#logo').attr({
src: "<%= asset_path('logo.png') %>"
});
A must read to make up your mind: http://guides.rubyonrails.org/asset_pipeline.html
Upvotes: 0
Reputation: 32037
Asset path requires an argument and you're not passing one, which is why it's exploding. The proper way to do this would be to use image_path
, which also requires an argument:
<%= image_tag("foo/blank.gif", {
:class =>"lazy",
:data => { "original" => image_path("foo/image-01.png")},
:alt => ""}) %>
Upvotes: 2