1

I have Product model which are items in the e-commerce store and is configured with paperclip to i can upload images for the product model.

When i add the image for the product, the image appears in /system/image/../.../.../thumbs and original but when i do

 <% for product in @products %>
    <%= link_to product.image.url(:original)  %>

  <% end %>

it appears broken links (/system/image/missing.png) when i browse the page. Similar to doing a group of thumbnails - i am trying to achieve to get all the product images out like a thumbnail. (eg. photo gallery)

Other code include model are below:

class Product < ActiveRecord::Base
  attr_accessible :name, :price, :image

  has_attached_file :image, :styles => { :medium => "238x238>",
                                         :thumb => "100x100>" }

  do_not_validate_attachment_file_type :image

end

Controller:

  def index
   @products = Product.all
  end
muhammadn
  • 330
  • 3
  • 18

2 Answers2

1

Let the Paperclip know about the location of where to store/read the attachments.

Add the following options to has_attached_file:

:url => "/system/:class/:attachment/:id/:style/:basename.:extension",
:path => ":rails_root/public/system/:class/:attachment/:id/:style/:basename.:extension"
Raj
  • 22,346
  • 14
  • 99
  • 142
  • It is still the same, the URL shows /system/images/missing.png. Is it something wrong with my paperclip? It is version 4.1.1 – muhammadn Jul 03 '14 at 14:09
0

Just to answer is someone stumbles upon this.

You will need to generate the paperclip Migration.

rails g paperclip Model attachment (for example: rails g paperclip User avatar) - the "attachment" is the one you defined in "has_attached_file".

Secondly, you need to add:

attr_accessible :image, :image_file_name, :image_content_type

i did that and viola! it worked!

muhammadn
  • 330
  • 3
  • 18