简体   繁体   中英

image_tag not showing paperclip uploaded image

Hi i'm using paperclip to upload and save the company avatar on my app. This is how it looks on company model:

has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/

I'm also using an initializer, paperclip.rb:

Paperclip::Attachment.default_options[:storage] = :fog
Paperclip::Attachment.default_options[:fog_credentials] = {:provider => "Local", :local_root => "#{Rails.root}/public"}
Paperclip::Attachment.default_options[:fog_directory] = ""
Paperclip::Attachment.default_options[:fog_host] = "http://localhost:3000"

Images are saved correctly, but when i try to display them like this:

<%= image_tag @company.avatar.url(:thumb) %>

It only shows the name of the file and no image.

The html looks like this:

<img alt="Mini cooper" src="http://localhost:3000/companies/avatars/000/000/003/thumb/mini-cooper.jpg%3F1416616058">

And if i take out the characters after .jpg like the following:

http://localhost:3000/companies/avatars/000/000/003/thumb/mini-cooper.jpg

I see the image just fine. But the helper just builds the url with those extra characters. Any ideas?

Looks like your issue is related to a recent commit which doesn't properly escape the timestamp. A temporary workaround is to disable the timestamp while a fix is worked-out.

For individual calls

@company.avatar.url(:thumb, timestamp:false)

Or you can disable this globally but putting the following line within your config/initializers/paperclip.rb file.

Paperclip::Attachment.default_options[:use_timestamp] = false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM