簡體   English   中英

image_tag未顯示回形針上傳的圖像

[英]image_tag not showing paperclip uploaded image

嗨,我正在使用回形針上載公司頭像並保存在我的應用程序中。 這是公司模型的外觀:

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

我還使用了一個初始化程序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"

圖像正確保存,但是當我嘗試像這樣顯示它們時:

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

它僅顯示文件名,沒有圖像。

html看起來像這樣:

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

如果我取出.jpg之后的字符,如下所示:

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

我看到圖像很好。 但是幫助程序只是使用這些額外的字符來構建url。 有任何想法嗎?

看來您的問題與最近提交有關,而該提交未能正確逃避時間戳。 臨時的解決方法是在解決問題時禁用時間戳。

對於個人電話

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

或者,您可以全局禁用此功能,但將以下行放入config/initializers/paperclip.rb文件中。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM