嘿,所以我试图在模型中使用模型的 :id 属性,但我无法弄清楚。
require 'zip/zip'
require 'zip/zipfilesystem'
class Lesson < ActiveRecord::Base
attr_accessible :attachment, :course_id, :goal, :title, :assets_attributes
belongs_to :course
has_many :assets, :dependent => :destroy
accepts_nested_attributes_for :assets, :reject_if => lambda { |a| a[:asset_file_name].blank? }
def bundle
bundle_filename = 'public/attachments/#{@lesson.id}.zip'
Zip::ZipFile.open(bundle_filename, Zip::ZipFile::CREATE) {
|zipfile|
self.assets.collect {
|asset|
zipfile.add( "#{asset.id}", "public/attachments")
}
}
File.chmod(0644, bundle_filename)
self.save
end
end
我在 bundle_filename = 'public/attachments/#{@lesson.id}.zip' 中遇到问题
特别是@lesson.id 部分。
有任何想法吗?