I have a model that uses paperclip like this:
has_attached_file :avatar, :styles => { :large => "100x100>" , :medium => "50x50>", :small => "20x20>" }, :default_url => '/images/missing-owner_:style.png'
I'm exporting this model with to_json method and I want to export the image url so I could use it in javascript.
I know I can access the url like this in the view:
<%= image_tag model.avatar.url(:medium) %>
But How can I do the same in the to_json method.
I have some like this:
respond_to do |format|
render :json => @model.to_json(:only => [:id,:name,:homephone,:cellphone])
end
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…