我有一个这样的模型:
# == Schema Information
#
# Table name: s3_files
#
# id :integer not null, primary key
# owner :string(255)
# notes :text
# created_at :datetime not null
# updated_at :datetime not null
# last_accessed_by_user :string(255)
# last_accessed_time_stamp :datetime
# upload_file_name :string(255)
# upload_content_type :string(255)
# upload_file_size :integer
# upload_updated_at :datetime
#
class S3File < ActiveRecord::Base
#PaperClip methods
attr_accessible :upload
attr_accessor :owner
Paperclip.interpolates :prefix do |attachment, style|
I WOULD LIKE TO ACCESS VARIABLE= owner HERE- HOW TO DO THAT?
end
has_attached_file( :upload,
:path => ":prefix/:basename.:extension",
:storage => :s3,
:s3_credentials => {:access_key_id => "ZXXX",
:secret_access_key => "XXX"},
:bucket => "XXX"
)
#Used to connect to users through the join table
has_many :user_resource_relationships
has_many :users, :through => :user_resource_relationships
end
我在控制器中设置这个变量,如下所示:
# POST /s3_files
# POST /s3_files.json
def create
@s3_file = S3File.new(params[:s3_file])
@s3_file.owner = current_user.email
respond_to do |format|
if @s3_file.save
format.html { redirect_to @s3_file, notice: 'S3 file was successfully created.' }
format.json { render json: @s3_file, status: :created, location: @s3_file }
else
format.html { render action: "new" }
format.json { render json: @s3_file.errors, status: :unprocessable_entity }
end
end
end
谢谢,任何帮助将不胜感激。