Guest User

Untitled

a guest
Feb 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. class Image < ActiveRecord::Base
  2. belongs_to :gallery
  3.  
  4. ...
  5.  
  6. def file=(incoming_file)
  7. @temp_file = incoming_file
  8. @filename = incoming_file.original_filename
  9. if !incoming_file.original_filename.blank?
  10. # Make sure the directory exists for us to save into
  11. FileUtils.mkdir_p(File.expand_path("public/images", RAILS_ROOT))
  12.  
  13. # Set file to unique timestamp plus original extension
  14. self.path = "/images/#{@gallery}." + incoming_file.original_filename.gsub(/.*\./, '')
  15. File.open(self.absolute_path(:original), File::CREAT|File::WRONLY) { |f| f.write(incoming_file.read) }
  16. end
  17. end
  18.  
  19. ...
  20. end
Add Comment
Please, Sign In to add comment