问题
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
回答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"
回答2:
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!
来源:https://stackoverflow.com/questions/24550464/views-shows-uploaded-paperclip-images-as-original-missing-png