如何根据用户性别和资产风格设置 Paperclip :default_url? [英] How to set Paperclip :default_url according User gender and asset style?
本文介绍了如何根据用户性别和资产风格设置 Paperclip :default_url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过这个要点脚本,我可以获得用户性别.但我也想得到 :style .有人知道怎么做吗?
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?
推荐答案
这样做的默认方式:
#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
或使用 lambda:
or using lambda:
has_attached_file :attachment, default_url: lambda{|attachment| "somedirectory/:style/:class/#{attachment.instance.gender}.png" }
在 Rails 4 中测试.
Tested in Rails 4.
这篇关于如何根据用户性别和资产风格设置 Paperclip :default_url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文