所以我在rails 3.2上加载了带有图像的徽章
badges = [ {id: 1, name: 'Democratic-Society', description: "Voted for two bands", image: "demo_society2.gif"}
]
badges.each do |badge|
Merit::Badge.create!(badge)
end
但我刚刚将我的代码服务器更新为Rails 4.1 ......现在它出现以下错误:
undefined method `image' for #<Merit::Badge:0x007f57949ba8f0>
我没有更改全部代码。没有触及优点初始值设定项......或者application.rb ...没有。无法弄清楚为什么它不起作用。这是来自application.rb的代码:
<% current_user.badges.each do |badge| %>
<%= image_tag (badge.image), :alt => badge.description, :float => "left" %>
<% end %>
任何帮助都将不胜感激。
答案 0 :(得分:1)
好的解决方案(如果其他人遇到此问题)与&#34; custom_fields&#34;有关。任何自定义字段都必须这样引用(出于某种原因,你并不真的需要在Rails 3.2中这样做,但你在Rails 4.1中这样做)
所以我所做的就是将代码更改为:
badges = [ {id: 1, name: 'Democratic-Society', description: "Voted for two bands", custom_fields: {image: "demo_society2.gif"} }]
然后在我看来:
<%= image_tag (badge.custom_fields[:image]), :alt => badge.description, :float => "left" %>
和VOILA!
在github上获得marcosgugs的解决方案。