Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Image < ActiveRecord::Base
- belongs_to :gallery
- ...
- def file=(incoming_file)
- @temp_file = incoming_file
- @filename = incoming_file.original_filename
- if !incoming_file.original_filename.blank?
- # Make sure the directory exists for us to save into
- FileUtils.mkdir_p(File.expand_path("public/images", RAILS_ROOT))
- # Set file to unique timestamp plus original extension
- self.path = "/images/#{@gallery}." + incoming_file.original_filename.gsub(/.*\./, '')
- File.open(self.absolute_path(:original), File::CREAT|File::WRONLY) { |f| f.write(incoming_file.read) }
- end
- end
- ...
- end
Add Comment
Please, Sign In to add comment