我有三個與回形針和AWS S3相關的問題。回形針自定義內插(也稱爲AWS S3的自定義路徑)
1)在我的模型,該模型具有回形針,我有以下代碼:
has_attached_file :attachment,
:url => "/songs/:user_id/:basename.:extension",
:path => "/songs/:user_id/:basename.:extension"
什麼是URL和路徑之間的區別?
2)什麼是:basename.:extension
?
3)假設有兩種型號:User
和File
。 User
有很多File
。回形針路徑和URL在File
模型中配置。
在config/initializers/paperclip.rb
,我把下面的代碼:
Paperclip.interpolates :user_id do |attachment, style|
attachment.instance.criteria.user_id
end
我確認上面的代碼是工作的罰款。我的文件被保存在songs/5/song.mp3
。我想保存MP3文件在songs/user_id_5/song.mp3
。我在下面嘗試做,但它不起作用。
Paperclip.interpolates :user_id do |attachment, style|
'user_id_' + attachment.instance.criteria.user_id
end
我該如何做到這一點?
對於#3,字符串不起作用。不知道爲什麼。 – JoHksi
所以如果你的'has_attached_file'方法中有':path =>「:user_id」...',那麼路徑的值是多少? –