fix validate upload file

parent 8829b3b6
Pipeline #1405 failed with stages
in 0 seconds
...@@ -3,9 +3,8 @@ class ApplyJob < ApplicationRecord ...@@ -3,9 +3,8 @@ class ApplyJob < ApplicationRecord
belongs_to :job belongs_to :job
has_one_attached :cv has_one_attached :cv
validates :name, presence: true, length: { maximum: 200 } validates :name, presence: true, length: { maximum: 200 }
VALID_FILE_UPLOAD = %w[application/msword application/pdf application/xls application/xlsx application/zip].freeze
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 255 }, format: { with: VALID_EMAIL_REGEX } validates :email, presence: true, length: { maximum: 255 }, format: { with: VALID_EMAIL_REGEX }
validates :cv, presence: true, content_type: { in: VALID_FILE_UPLOAD, message: 'must be a valid pdf format' }, validates :cv, presence: true, content_type: { in: 'application/pdf', message: 'must be a valid pdf format' },
size: { less_than: 5.megabytes, message: 'should be less than 5MB' } size: { less_than: 5.megabytes, message: 'should be less than 5MB' }
end end
...@@ -3,12 +3,11 @@ class User < ApplicationRecord ...@@ -3,12 +3,11 @@ class User < ApplicationRecord
has_many :apply_jobs, dependent: :destroy has_many :apply_jobs, dependent: :destroy
has_many :favorite_jobs, dependent: :destroy has_many :favorite_jobs, dependent: :destroy
has_many :history_jobs, dependent: :destroy has_many :history_jobs, dependent: :destroy
VALID_FILE_UPLOAD = %w[application/msword application/pdf application/xls application/xlsx application/zip].freeze
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :recoverable, :rememberable, :trackable, :validatable,
:confirmable :confirmable
validates :name, length: { maximum: 200 } validates :name, length: { maximum: 200 }
validates :email, length: { maximum: 200 }, uniqueness: true validates :email, length: { maximum: 200 }, uniqueness: true
validates :cv, content_type: { in: VALID_FILE_UPLOAD, message: 'must be msword, pdf, xls, xlsx, zip format' }, validates :cv, content_type: { in: 'application/pdf', message: 'must be a valid pdf format' },
size: { less_than: 5.megabytes, message: 'should be less than 5MB' } size: { less_than: 5.megabytes, message: 'should be less than 5MB' }
end end
\ No newline at end of file
...@@ -41,6 +41,6 @@ h2.p-3.text-center ...@@ -41,6 +41,6 @@ h2.p-3.text-center
.field .field
= f.label :cv, "CV" = f.label :cv, "CV"
br br
= f.file_field :cv, accept: User::VALID_FILE_UPLOAD, size: { less_than: 5.megabytes, message:"should be less than 5MB" } = f.file_field :cv, accept: 'application/pdf', size: { less_than: 5.megabytes, message:"should be less than 5MB" }
.actions.p-2.text-center .actions.p-2.text-center
= f.submit "Update", class: "btn btn-primary" = f.submit "Update", class: "btn btn-primary"
\ No newline at end of file
...@@ -30,6 +30,6 @@ h2.p-3.text-center ...@@ -30,6 +30,6 @@ h2.p-3.text-center
.field .field
= f.label :cv, "CV" = f.label :cv, "CV"
br br
= f.file_field :cv, accept: User::VALID_FILE_UPLOAD, size: { less_than: 5.megabytes, message:"should be less than 5MB" } = f.file_field :cv, accept: 'application/pdf', size: { less_than: 5.megabytes, message:"should be less than 5MB" }
.actions.p-3.text-center .actions.p-3.text-center
= f.submit "Sign up", class: "btn btn-primary" = f.submit "Sign up", class: "btn btn-primary"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment