Guest User

Untitled

a guest
May 16th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. class EpisodeImage < ActiveRecord::Base
  2. belongs_to :episode
  3.  
  4. has_attachment :content_type => :image,
  5. :storage => :file_system,
  6. :max_size => 500.kilobytes,
  7. :resize_to => '276x155>',
  8. :processor => "MiniMagick"
  9.  
  10. attr_accessible :uploaded_data
  11.  
  12. def validate
  13. errors.add_to_base("Нужно загрузить кадр эпизода") unless self.filename
  14.  
  15. unless self.filename.blank?
  16.  
  17. # Images should only be GIF, JPEG, or PNG
  18. [:content_type].each do |attr_name|
  19. enum = attachment_options[attr_name]
  20. unless enum.nil? || enum.include?(send(attr_name))
  21. errors.add_to_base("Можно загружать только файлы изображений")
  22. end
  23. end
  24.  
  25. # Images should be less than 5 MB
  26. [:size].each do |attr_name|
  27. enum = attachment_options[attr_name]
  28. unless enum.nil? || enum.include?(send(attr_name))
  29. errors.add_to_base("Слишком большой размер файла с изображением, попробуйте сжать исходное изображение или выбрать другое")
  30. end
  31. end
  32.  
  33. end
  34. end
  35. end
Add Comment
Please, Sign In to add comment