Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class EpisodeImage < ActiveRecord::Base
- belongs_to :episode
- has_attachment :content_type => :image,
- :storage => :file_system,
- :max_size => 500.kilobytes,
- :resize_to => '276x155>',
- :processor => "MiniMagick"
- attr_accessible :uploaded_data
- def validate
- errors.add_to_base("Нужно загрузить кадр эпизода") unless self.filename
- unless self.filename.blank?
- # Images should only be GIF, JPEG, or PNG
- [:content_type].each do |attr_name|
- enum = attachment_options[attr_name]
- unless enum.nil? || enum.include?(send(attr_name))
- errors.add_to_base("Можно загружать только файлы изображений")
- end
- end
- # Images should be less than 5 MB
- [:size].each do |attr_name|
- enum = attachment_options[attr_name]
- unless enum.nil? || enum.include?(send(attr_name))
- errors.add_to_base("Слишком большой размер файла с изображением, попробуйте сжать исходное изображение или выбрать другое")
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment