我有一個方法的模型返回一個URL一個人的頭像,看起來像這樣:如何從模型中引用資產管道中的圖像?
def avatar_url
if self.avatar?
self.avatar.url # This uses paperclip
else
"/images/avatars/none.png"
end
end
我在升級之中到3.1,所以現在的硬編碼的圖像基本沒有需求通過資產管道引用。在控制器或視圖中,我只是將它包裝在image_path()
中,但我沒有在模型中使用該選項。我怎樣才能生成正確的網址到圖像?
另一種選擇:http://stackoverflow.com/questions/9646549/default-url-in-paperclip-broke-with-asset-pipeline-upgrade – James