通过this gist脚本,我可以获得用户性别的回形针的默认网址。但我想得到:风格也是如此。有人知道怎么做?
答案 0 :(得分:2)
默认方式:
#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:
has_attached_file :attachment, default_url: lambda{|attachment| "somedirectory/:style/:class/#{attachment.instance.gender}.png" }
在Rails 4中测试。