2015-11-22 26 views
2

將我的RoR應用程序與AWS集成以存儲用戶的Facebook照片時,照片將存儲爲「原始」而非「中」。AWS RoR - 不將照片存儲爲介質;而是原始

這裏是我的用戶模型中的相關信息:

class User < ActiveRecord::Base 

    has_attached_file :avatar, 
        :storage => :s3, 
        :style => {:medium => "370x370", :thumb => "100x100"} 

    validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/ 

調用原始照片是成功的,但我需要的媒體縮略圖,因爲顯示的照片作爲原來提出的審美問題。

這裏是我的_user.html.erb用戶文件中的相關信息:

<div class="img"><%= image_tag user.avatar.url(:original), height: "370", width: "370" %> </div> 

但是,就像我說的,我不希望把原來的,我想從AWS調用該文件,像這樣:

<%= image_tag user.avatar.url(:medium) 

當我檢查頁面時,我看到「:medium」它沒有被保存,所以我會認爲這是模型user.rb的問題,但是非常感謝所有幫助,因爲我一直在這個問題上停留了很長時間。

+0

我假設你使用回形針,對嗎? – Undo

回答

0

我假設你需要先設置驗證器。我認爲PaperClip關心圖像大小。所以在你的型號中:

validates_with AttachmentSizeValidator, :attributes => :avatar, :less_than => 1.megabytes 

這對我有效。

相關問題