From e9f5ee5303b3a4c4064c58fe7e0c73ac2642bb06 Mon Sep 17 00:00:00 2001 From: James Beavers Date: Sun, 21 Sep 2014 01:38:12 -0400 Subject: [PATCH] Combine types of user models into just one (use controller to restrict based on roles) and add resume model --- app/models/jobseeker.rb | 3 --- app/models/post.rb | 8 -------- app/models/resume.rb | 5 +++++ app/models/user.rb | 23 ++++++++++++++--------- 4 files changed, 19 insertions(+), 20 deletions(-) delete mode 100644 app/models/jobseeker.rb delete mode 100644 app/models/post.rb create mode 100644 app/models/resume.rb diff --git a/app/models/jobseeker.rb b/app/models/jobseeker.rb deleted file mode 100644 index fe4d723..0000000 --- a/app/models/jobseeker.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Jobseeker < ActiveRecord::Base - has_and_belongs_to_many :roles -end \ No newline at end of file diff --git a/app/models/post.rb b/app/models/post.rb deleted file mode 100644 index 851fd38..0000000 --- a/app/models/post.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Post < ActiveRecord::Base - belongs_to :users - validates :title, :presence => true, :length => {:maximum => 30} - validates :body, :presence => true, :length => {:maximum => 500} - - scope :drafts, where("draft = ?", true) - scope :published, where("draft = ?", false) -end diff --git a/app/models/resume.rb b/app/models/resume.rb new file mode 100644 index 0000000..6f0f313 --- /dev/null +++ b/app/models/resume.rb @@ -0,0 +1,5 @@ +class Resume < ActiveRecord::Base + belongs_to :jobseekers + validates :title, :presence => true, :length => {:maximum => 128} + validates :body, :presence => true, :length => {:maximum => 10000} +end diff --git a/app/models/user.rb b/app/models/user.rb index d721376..3ce01b7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,12 @@ class User < ActiveRecord::Base + has_and_belongs_to_many :roles + has_many :permissions, :through => :roles + has_many :skills + has_and_belongs_to_many :jobs + + accepts_nested_attributes_for :roles + accepts_nested_attributes_for :skills + devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :timeoutable @@ -9,12 +17,9 @@ class User < ActiveRecord::Base validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false } - - has_and_belongs_to_many :roles - has_many :permissions, :through => :roles - has_many :posts, :foreign_key => "owner_id" - - accepts_nested_attributes_for :roles + VALID_PHONE_REGEX = /^(\([0-9]{3}\) |[0-9]{3}-|[0-9]{3})[0-9]{3}-[0-9]{4}$/ + validates :phone, + format: { with: VALID_PHONE_REGEX } def has_permission? perm self.permissions.pluck(:name).include? perm @@ -28,7 +33,7 @@ def is_admin? self.has_permission? "application_admin" end - def can_publish? - self.has_permission? "can_publish" + def can_post? + self.has_permission? "can_post" end -end +end \ No newline at end of file