嘿,所以我有一个名为 Asset 的类,每个 Asset 都有一个:附件。我想获取上传文件的 :basename.:extension 并将其存储在 :asset_file_name 中。我该怎么做呢?这是我的课:
class Asset < ActiveRecord::Base
attr_accessible :asset_file_name, :lesson_id, :attachment
#allows us to use :lesson_id in :url
Paperclip.interpolates :lesson_id do |attachment, style|
attachment.instance.lesson_id
end
has_attached_file :attachment,
:url => "/attachments/:lesson_id/:basename.:extension",
:path => ":rails_root/public/attachments/:lesson_id/:basename.:extension"
validates_presence_of :asset_file_name
validates_attachment_presence :attachment
end