[英]rails paperclip no direct access through sql query from another model
if tried to access paperclip images from another model to show in its view through a sql query, it wont show the images. 如果试图从另一个模型访问回形针图像,通过SQL查询在其视图中显示,它将不会显示图像。
i tried something like this from a category controller wch takes in params from a form, in the index page, thru select box. 我从类别控制器中尝试了类似这样的东西,从索引页面,通过选择框获取表格中的参数。
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
in the show page, i cannot access the paperclip attribute wch is in the listing model, from the category controller. 在显示页面中,我无法从类别控制器访问列表模型中的回形针属性。
category show page
<% @category.each do |c| %>
<%= c.place %>
<%= image_tag c.placeholder.url(:thumb) %>
<% end %>
listing and category have the habtm relation 列表和类别具有habtm关系
This is an old post but I had run into the same problem and was an easy fix with the correct query and the same loop you already have but my issue was in Rails 4. 这是一个旧帖子,但我遇到了同样的问题,并且使用正确的查询和您已经拥有的相同循环进行了简单的修复,但我的问题是在Rails 4中。
For those who have this issue in the future try using 对于那些将来有这个问题的人尝试使用
Category.where(:id => params[:id])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.