【发布时间】:2012-01-19 19:40:32
【问题描述】:
当我在我的视图中运行这行代码时,
<%= image_tag(item.picture.url(:medium), :class => "iteminfo") %>
我得到一个
undefined method `symbolize_keys'
错误。我目前正在使用带有 S3 存储的回形针 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)
【问题讨论】:
-
你能添加整个回溯吗?
-
Item.first.picture.url(:medium)在控制台中工作吗 -
另外,不相关但看看each_with_index,比手动设置循环计数要干净一些
-
感谢 each_with_index 提示!我总是觉得 sn-p 非常丑陋,但我不知道更好的方法。老实说,我认为不会。我的数据库有点像一场噩梦,一台死机的笔记本电脑目前不允许我检查。你认为这可能是一个原因吗?
-
如果它在控制台中不起作用,那么这根本不是视图问题,那将是我要检查的第一件事。
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 heroku paperclip