I have a model; I do photo = Photo.new(parameters) parameters
contains:
{"picture"=>#<File:C:/DOCUME~1/BART~1/LOCALS~1/Temp/CGI3180.1>}
so i expect that the def picture=(filename) method is called in this
constructor.. this is not the case. Does anyone know why?
params[:photo].each_pair do |id, parameters|
photo = Photo.new(parameters)
end
class Photo < ActiveRecord::Base
attr_accessor :file, :content_type, :size, :extension, :local_path, :destroyed
attr_reader :original_filename
attr_accessible :title, :description
has_many :comments, :exclusively_dependent => true
belongs_to :user
validates_presence_of :title
validates_presence_of :description, :on => :update
acts_as_taggable
def picture=(picture_field)
logger.debug "in picture method" ## DEBUGGING
@local_path = picture_field.local_path
@filename = base_part_of(picture_field.original_filename)
@extension = @filename.split(''.'').pop
if @extension == "jpeg"
@extension = "jpg" ## convention
end
@content_type = picture_field.content_type.chomp
@size = picture_field.size
picture_field.rewind
@file = picture_field.read
self.title = @filename
end
..
end