我的Ruby on Rails应用程序中有以下模型,它使用paperclip进行上传:
class SlideAudio < ApplicationRecord
# == Extensions ============================================================
Paperclip.interpolates :locale do |attachment, style|
attachment.instance.locale
end
has_attached_file :audio,
path: ":rails_root/public/slides/:attachment/:style/:locale/:id.:extension",
url: "/slides/:attachment/:style/:locale/:id.:extension",
processors: [:audio_compression],
styles: {
original: {},
compressed_96k: {bitrate: '96k'}
}
# == Associations ==========================================================
has_many :slide_slide_audios
has_many :slides, through: :slide_slide_audios
# == Validations ===========================================================
validates_attachment :audio, content_type: {
content_type: [
'audio/mpeg',
'audio/x-mpeg',
'audio/mp3',
'audio/x-mp3',
'audio/mpeg3',
'audio/x-mpeg3',
'audio/mpg',
'audio/x-mpg',
'audio/x-mpegaudio'
]
}
end
上传一个音频后,我有两个文件:
public/slides/audios/original/en/30381.mp3
public/slides/audios/compressed_96k/en/30381.mp3
不,我想将所有这些文件名更新为18695.mp3
。我怎么能这样做?