我想建立一个相当简单的图像链接,该链接使用我的资产中的图像。得到奇怪的错误。首先,我尝试了:

<%= link_to assets_path "town.png", 'index' %>

并有错误

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'

然后我尝试了旧

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

并遇到了这个奇怪的错误

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'

该怎么办?

有帮助吗?

解决方案

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

放一些括号

其他提示

你需要一些 ()

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

另外,您需要使用 image_tag

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

如果您希望它本身带有图像的另一页

是的,有些括号可能会有所帮助。尝试这样的事情:

<%= link_to(image_tag("town.png", :alt => 'Town Image'), index_url) %>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top