Jump to content

The ultimate community for Ruby on Rails developers.


Proper way of retrieving image info from PaperClip

  • Please log in to reply
No replies to this topic

#1 Ohm



  • Moderators
  • 529 posts
  • LocationCopenhagen

Posted 18 October 2013 - 05:21 AM

I have a Sign model with the following

has_attached_file :image,
                  styles: {
                    medium: "300x300>",
                    thumb: "100x100>"
                  default_url: 'signs/:style/missing.png'

I want to do a ActiveRecord select, where I only retrieve what I need for the view. In the view I have

<% @signs.each do |sign| %>
  <%= sign.name -%>: <%= image_tag sign.image(:medium) -%>
<% end %>

How would I write the select? I've tried

Sign.select(:name, :image) # Doesn't work
--- AND ---
Sign.select(:name, :image_file_name, :image_content_type, :image_file_size, :image_updated_at)

The last one gives me all the correct info, however I get an "NoSuchKey" when I try to render the image. Also the url only seems to be 


Missing something between the two /. It works fine if I do a 


instead of trying to select the proper fields.

Blog: http://ohm.sh | Twitter: @madsohm | Work: Lokalebasen.dk

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users