当我在我的视图中运行这行代码时,
<%= image_tag(item.picture.url(:medium), :class => "iteminfo") %>
我得到了
undefined method `symbolize_keys'
错误。我目前正在使用带有S3存储的paperclip gem。有什么建议?
- 编辑:
以下是服务器日志的内容:
Started GET "/items/compare" for 127.0.0.1 at 2012-01-19 14:47:21 -0500
Processing by ItemsController#compare as HTML
(0.1ms) SELECT items.id FROM "items"
Item Load (0.2ms) SELECT "items".* FROM "items" WHERE "items"."id" IN (3, 2)
Rendered items/compare.html.erb within layouts/application (37.3ms)
Completed 500 Internal Server Error in 99ms
ActionView::Template::Error (undefined method `symbolize_keys' for #<String:0x007f9ebccd92b0>):
3: <% @items.each do |item| %>
4: <div class="item<%= loopcount %>">
5: <% loopcount = loopcount +1%>
6: <%= image_tag(item.picture.url(:medium), :class => "iteminfo") %> <blockquote> </blockquote>
7: <h2 class = "iteminfotext"><%= item.votes %></h2>
8: <h1 class = "iteminfotext"><%= item.location %></h1>
9: <div class="iteminfotext"><%= button_to "Vote", :action => "vote", :id => item.id, %></div>
app/views/items/compare.html.erb:6:in `block in _ app_views_items_compare_html_erb___818922328118740053_70159882605160'
app/views/items/compare.html.erb:3:in `each'
app/views/items/compare.html.erb:3:in ` _app_views_items_compare_html_erb___818922328118740053_70159882605160'
Rendered /Users/Alex/.rvm/gems/ruby-1.9.2-p290/gems/actionpack- 3.1.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms)
Rendered /Users/Alex/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms)
Rendered /Users/Alex/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (3.8ms)
答案 0 :(得分:0)
这是一种铁轨或回形针问题。如果你这样做
<%= image_tag(item.picture.url(:medium), :class => "iteminfo") %>
除非您将其更改为
之类的链接,否则它将无效<%= link_to image_tag(item.picture.url(:medium), :class => "iteminfo"), item_path(item) %>
否则你总会得到
undefined method `symbolize_keys'
要避免这种情况,您只需重建图像标记块,使其看起来像这样
<%= image_tag(item.picture.url(:medium)), :class => "iteminfo" %>
或
<%= image_tag(item.picture(:medium)), :class => "iteminfo" %>
那么你的问题就解决了
更新
<%= image_tag item.picture.url(:medium), :class => "iteminfo" %>
<%= image_tag item.picture(:medium), :class => "iteminfo" %>