我想製作一個相當簡單的圖像鏈接,使用我資產中的圖像。得到奇怪的錯誤。首先我想:Rails 3.1,無法使link_to image_path?
<%= 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'
怎麼辦?
有些支架可能會幫助到另一個頁面圖像。 Rails可能無法理解您提供的選項。也許更像是:'<%= link_to(image_tag(「town.png」,:alt =>'Town Image'),index_url)%>' – Pete
@zoltarSpeaks將您的評論發佈爲答案。它看起來不錯 – lucapette
@zoltarSpeaks是。作爲回答發佈,所以我可以接受。我以爲我嘗試過......但我猜不是。我們。謝謝 – varatis