如果尝试从另一个模型访问回形针图像以通过 sql 查询在其视图中显示,它不会显示图像。
我从一个类别控制器尝试了这样的事情,它通过选择框从表单中获取参数,在索引页面中。
category controller
def show
@category = 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
在显示页面中,我无法从类别控制器访问列表模型中的回形针属性。
category show page
<% @category.each do |c| %>
<%= c.place %>
<%= image_tag c.placeholder.url(:thumb) %>
<% end %>
Listing和category有habtm关系