Ruby on Rails How do I access variables of a model inside itself like in this example?
- by banditKing
I have a Model like so:
# == 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
Im setting this variable in the controller like so:
# 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
Thanks, any help would be appreciated.