Reputation: 14740
I want to make a fairly straightforward image link that uses an image from my assets. Getting weird errors. First I tried:
<%= link_to assets_path "town.png", 'index' %>
and got the error
Started GET "/" for 127.0.0.1 at Wed Nov 30 17:27:10 -0500 2011
Processing by PagesController#intro as HTML
Rendered pages/intro.html.erb within layouts/application (114.9ms)
Completed 500 Internal Server Error in 124ms
ActionView::Template::Error (undefined method `assets_path' for #<#<Class:0x10fdc4898>:0x10fdaad58>):
1: <body onload="init();">
2: <div id = "wrapper2">
3: <div class="intro_txt">
4: <%= link_to assets_path "town.png", 'index' %>
5: <br><br>
6: </div>
7: </div>
app/views/pages/intro.html.erb:4:in `_app_views_pages_intro_html_erb__1651075534_2280428740'
then I tried the old
<%= link_to image_tag "town.png", 'index' %>
and got this bizarre error
ActionView::Template::Error (undefined method `symbolize_keys!' for "index":String):
1: <body onload="init();">
2: <div id = "wrapper2">
3: <div class="intro_txt">
4: <%= link_to image_tag "townProjectText.png", 'index' %>
5: <br><br>
6: </div>
7: </div>
app/views/pages/intro.html.erb:4:in `_app_views_pages_intro_html_erb__1651075534_2279838600'
What to do?
Upvotes: 0
Views: 2713
Reputation: 75
<%= link_to image_tag("town.png"), image_path %>
if you want it to go to another page with the image by itself
Upvotes: 1
Reputation: 1482
Yeah some brackets would perhaps help. Try something like this:
<%= link_to(image_tag("town.png", :alt => 'Town Image'), index_url) %>
Upvotes: 0
Reputation: 77778
You need some ()
<%= link_to image_tag("town.png"), pages_path %>
Also, you need to use image_tag
Upvotes: 3
Reputation: 27463
<%= link_to image_tag('town.png'), 'index' %>
Put some parentheses
Upvotes: 4