问题
if tried to access paperclip images from another model to show in its view through a sql query, it wont show the images.
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
回答1:
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.
For those who have this issue in the future try using
Category.where(:id => params[:id])
来源:https://stackoverflow.com/questions/19756998/rails-paperclip-no-direct-access-through-sql-query-from-another-model