【发布时间】:2013-11-04 01:24:04
【问题描述】:
我的应用程序有一个 habtm 关系 b/w 列表和类别。现在从类别索引页面,用户过滤选择框以查看显示页面中的列表。
现在我无法访问附加到类别显示页面中列表的图像。
listing.rb
attr_accessible :placeholder, :categories_ids
has_and_belongs_to_many :categories
has_attached_file :placeholder, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png",
:url => "/system/:hash.:extension",
:hash_secret => "longSecretString"
类别控制器
def index
@categories = Category.all
end
def show
@categories = Category.find_by_sql ["select distinct l.* from listings l , categories c, categories_listings cl where c.id = cl.category_id and l.id = cl.listing_id and c.id in (?,?)" , params[:c][:id1] , params[:c][:id2]]
end
sql 只是过滤并显示显示页面中的列表,我可以在其中显示其属性,但无法访问占位符。注意 show 中的复数 @categories
分类显示页面
<ul>
<% @categories.each_with_index do |c, index| %>
<% if index == 0 %>
<li class="first"><%= c.place %></li>
<%= image_tag c.placeholder.url(:thumb) %>
<li><%= c.price %></li>
<% else %>
<li><%= c.place %></li>
<li><%= c.price %></li>
<%= image_tag c.placeholder.url(:thumb) %>
<% end %>
<% end %>
</ul>
Access image from different view in a view with paperclip gem ruby on rails
这表示使对象复数并调用循环,wch 应允许访问图像。
在这种情况下不起作用。
undefined method `placeholder' for #<Category:0x5c78640>
但令人惊奇的是,如果按照 stackoverflow 中的建议使用,占位符将显示为所有列表的所有图像的数组,显然,wch 不是我喜欢的方式。问题出在哪里?我错过了什么?
【问题讨论】:
-
您在 category.rb 模型中是否设置了相关的
has_and_belongs_to_many关系? -
一切都是 der。我可以在类别显示页面中显示列表及其所有属性,但不能显示占位符图像。
-
你在分类数据库中有占位符图像列吗?
-
没有。我想如何设置它并将其链接到列表模型。此外,回形针根据占位符生成 4 列。它是如何工作的,只调用占位符。
-
对不起,我想我把你弄糊涂了!我真正的意思是“您是否根据需要设置了回形针列,它们是否在标准情况下工作?”
标签: ruby-on-rails ruby ruby-on-rails-3 paperclip