简体   繁体   English

Rails 3.1,无法建立link_to image_path吗?

[英]Rails 3.1, can't make link_to image_path?

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? 该怎么办?

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

加上一些括号

You need some () 您需要一些()

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

Also, you need to use image_tag 另外,您需要使用image_tag

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

如果您想让它单独转到带有图像的另一页

Yeah some brackets would perhaps help. 是的,有些括号也许会有所帮助。 Try something like this: 尝试这样的事情:

<%= link_to(image_tag("town.png", :alt => 'Town Image'), index_url) %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM