Skip to content

Commit 064611f

Browse files
committed
Add attribute, enum, validation, and scope to model
1 parent 487bb30 commit 064611f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

app/models/job_application.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class JobApplication < ApplicationRecord
22
attribute :status, :string
3+
attribute :location, :string
34

45
validates :date_applied, :company_name, :method_of_contact, :position_type, :position_title, presence: true
56
validates :email_address, presence: true, if: -> { method_of_contact == "email" }
@@ -13,6 +14,7 @@ class JobApplication < ApplicationRecord
1314
}
1415
validates :claimed_for_unemployment, inclusion: {in: [true, false]}
1516
validates :status, inclusion: {in: %w[hired interviewing job_offer no_response not_hired]}
17+
validates :location, inclusion: {in: %w[hybrid in_office remote]}
1618

1719
enum method_of_contact: {
1820
email: "email",
@@ -33,7 +35,13 @@ class JobApplication < ApplicationRecord
3335
no_response: "no response",
3436
not_hired: "not hired"
3537
}
38+
enum location: {
39+
hybrid: "hybrid",
40+
in_office: "in office",
41+
remote: "remote"
42+
}
3643

44+
scope :by_location, ->(location) { where(location: location) }
3745
scope :by_method_of_contact, ->(method) { where(method_of_contact: method) }
3846
scope :by_position_type, ->(type) { where(position_type: type) }
3947
scope :by_status, ->(status) { where(status: status) }
@@ -45,6 +53,7 @@ class JobApplication < ApplicationRecord
4553
email_address ILIKE :query OR
4654
point_of_contact ILIKE :query OR
4755
website_link ILIKE :query OR
56+
location ILIKE :query OR
4857
status ILIKE :query", query: "%#{query}%")
4958
}
5059
end

0 commit comments

Comments
 (0)