0

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?

Richard Hulse
  • 10,383
  • 2
  • 33
  • 37
varatis
  • 14,494
  • 23
  • 71
  • 114
  • 3
    Some brackets might help. It might that Rails isn't able to understand the options you've provided. Perhaps something a bit more like: `<%= link_to(image_tag("town.png", :alt => 'Town Image'), index_url) %>` – Pete Nov 30 '11 at 22:37
  • @zoltarSpeaks post your comment as an answer. It looks good – lucapette Nov 30 '11 at 22:38
  • 1
    @zoltarSpeaks Yup. post as answer so I can accept. I thought I had tried that... but I guess not. w/e. Thanks – varatis Nov 30 '11 at 22:44

4 Answers4

4
<%= link_to image_tag('town.png'), 'index' %>

Put some parentheses

Damien
  • 26,933
  • 7
  • 39
  • 40
3

You need some ()

<%= link_to image_tag("town.png"), pages_path %>

Also, you need to use image_tag

maček
  • 76,434
  • 37
  • 167
  • 198
1
<%= link_to image_tag("town.png"), image_path %> 

if you want it to go to another page with the image by itself

jrich
  • 75
  • 6
0

Yeah some brackets would perhaps help. Try something like this:

<%= link_to(image_tag("town.png", :alt => 'Town Image'), index_url) %>
Pete
  • 1,472
  • 2
  • 15
  • 32