Rails 3.1,无法将link_to设置为image_path吗? [英] Rails 3.1, can't make link_to image_path?

查看:85
本文介绍了Rails 3.1,无法将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' %>

出现错误

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' %>

放一些括号

这篇关于Rails 3.1,无法将link_to设置为image_path吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆