2012-12-01 67 views
1

我有一個用於模型的Paperclip的用戶模型,我需要能夠使用RABL爲每個尺寸(小,中,大)返回image_url使用RABL從Paperclip返回圖片URL

在mongoid模型,我只想做self.avatar(:original)但現在沒有什麼工作,我只是得到的附件的空響應

"user" : { 
    "id" : "50b204e10eae9c55fa000028", 
    "paperclip::attachment" : {}, 
    "name" : "My Name" 
} 

/models/user.rb

has_mongoid_attached_file :avatar, 
    :styles => { 
     :original => ['1000x1000>', :jpg], 
     :small => ['64x64#',   :jpg], 
     :medium => ['250x250', :jpg], 
     :large => ['500x500>', :jpg] 
    } 

/views/posts/base.json.rabl

child :user do 
    attributes :id, :name 

    child :avatar do 
     attributes :original 
    end 
end 

回答

1

試試這個:

child :user do 
    attributes :id, :name 

    node :avatar_original do |u| 
    u.avatar(:original) 
    end 
end