0

I want to add a validation for attachinary upload (:photo_presentation) it should be more than 0.5 megabytes, less than 2 megabytes, any idea please?

Here is my model :

class User < ApplicationRecord


  has_attachment :photo_presentation
  has_attachment :photo_company_logo

  has_many :projects, dependent: :destroy
  has_many :articles

  include FriendlyId
  friendly_id :company, :use => :slugged

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  #geocoder for google maps
  geocoded_by :address
  after_validation :geocode, if: :address_changed?

  validates :email, uniqueness: true, presence: true
  validates :company, presence: true, uniqueness: true
  validates :first_name, presence: true
  validates :last_name, presence: true
  validates :office_phone, uniqueness: true
  validates :mobile_phone, presence: true, uniqueness: true
  validates :address, presence: true
  validates :description, presence: true, length: { minimum: 300, maximum: 900 }
  validates :radius, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 50 }
  validates :city, presence: true
  validates :zip_code, presence: true
end

Thanks!

Tana
  • 31
  • 6

1 Answers1

0

you can try this command

validates_attachment :photo_presentation, :size => { :in => 0.5..2.megabytes } 
widjajayd
  • 6,090
  • 4
  • 30
  • 41
  • Thanks but already tried this : ===> undefined method `validates_attachment' for # – Tana Jun 27 '17 at 14:50
  • you may check this link https://github.com/assembler/attachinary/issues/10 it seems no config to limit file size – widjajayd Jun 27 '17 at 15:04
  • Yes hope this new addon is now availbale, that was on 2012...Thks for your help! – Tana Jun 27 '17 at 15:13