2016-11-23 48 views
2

我有以下代碼:Rails的管理員顯示:拇指圖像

config/initializers/rails_admin.rb

list do 
     field :id  #currentId set in app/views/rails_admin/main/index 
     field :year 
     field :title 
     field :intro 
     field :description 
     field :confidential 
     field :star 
     field :image do 
     formatted_value do 
      bindings[:view].tag(:img, { :src => bindings[:object].image.url(:thumb)}) 
     end 
     end 
    end 

app/models/submission.rb

class Submission < ActiveRecord::Base 

    # Image attachment and validations 
    has_attached_file :file, 
    :url => "/files/:class/:attachment/:id/:style/:basename.:extension", 
    :path => ":rails_root/public/files/:class/:attachment/:id/:style/:basename.:extension", 
    :styles => { :thumb => "100x100#", :small => "150x150>", :medium => "200x200" } 

    # Validate attachment type 
    validates_attachment_content_type :file, :content_type => 'application/pdf' 

end 

問題:在列表視圖中,爲什麼我沒有拿到那:thumb圖像和我得到一個非常大的圖像?我猜斬波程序根本不起作用?

+0

你有沒有創建新提交後添加這種風格的配置? –

+0

是的,我剛剛添加了一個新項目,圖像仍然顯示爲非常大! –

+0

:content_type =>'application/pdf'爲什麼要驗證PDF? –

回答

0

validates_attachment_content_type :file, :content_type => 'application/pdf' 

和你期望的圖像進行調整,我認爲你檢查你的模式和實施再

關注這個

https://github.com/thoughtbot/paperclip/wiki/Thumbnail-Generation

+0

我將大小調整爲正確的模型,但我仍然在索引頁上獲得巨大圖像 –

+0

請創建新項目 –

+0

或者Project.find_each {| u | u.file.reprocess! }爲了創建現有文件的縮略圖 –

相關問題