我有三个与回形针和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”...',那么路径的值是多少? –