How to set Paperclip :default_url according User gender and asset style?

こ雲淡風輕ζ 提交于 2019-12-11 07:45:28

问题


Through this gist script I can get default url for paperclip with user gender. But I want to get :style too. Someone know how to?


回答1:


Default way of doing this:

#Assuming you default images are stored in app/assets/images/somedirectory

has_attached_file :attachment, default_url: :some_function

def some_function
   "somedirectory/:style/:class/#{self.gender}.png"
end

or using lambda:

has_attached_file :attachment, default_url: lambda{|attachment| "somedirectory/:style/:class/#{attachment.instance.gender}.png" }

Tested in Rails 4.



来源:https://stackoverflow.com/questions/7288884/how-to-set-paperclip-default-url-according-user-gender-and-asset-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!