diff --git a/.gitignore b/.gitignore
index ca05a53..8ab09e6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,4 +19,7 @@ Gemfile.lock
# Ignore the .idea folder generated by RubyMine
.idea/
+
+# Ignore all public assets
+/public/*
# Add non-default ignores below
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index 3ab7800..a1db178 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -2,7 +2,7 @@ class RegistrationsController < Devise::RegistrationsController
def create
@user = User.create(params["user"])
- @user.roles << Role.find_by_name("Reporter")
+ @user.roles << Role.find_by_name("JobSeeker")
sign_in @user
redirect_to root_path
end
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index 995236f..28c2595 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -1,6 +1,41 @@
class UserController < ApplicationController
+ ##
+ # Function to list all the users.
+ # This is to be used by job seekers to list all the employers by name
+ ##
def index
- @users = User.all
+ @users = User.get_all_employers
+ end
+
+ ##
+ # Function for the editing of the used profile.
+ # Uses the user_params for update.
+ ##
+ def edit
+
+ end
+
+ ##
+ # Deletes a user.
+ # A user may chose to terminate his association with the job portal.
+ ##
+ def destroy
+
+ end
+
+ ##
+ # Function to update a resume.
+ # User model accepts nested resources for resume.
+ # One to One relationship for Resume and User.
+ ##
+ def update_resume
+
+ end
+
+ private
+
+ def user_params
+ params.require(:user).permit(:name, :email, :phone, :resume)
end
end
\ No newline at end of file
diff --git a/app/models/user.rb b/app/models/user.rb
index 4f5bf64..724467f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -3,7 +3,7 @@ class User < ActiveRecord::Base
has_and_belongs_to_many :jobs
has_many :permissions, :through => :roles
has_one :resume, :foreign_key => :owner_id
- has_one :role
+ has_and_belongs_to_many :roles
accepts_nested_attributes_for :roles
accepts_nested_attributes_for :skills
@@ -16,11 +16,14 @@ class User < ActiveRecord::Base
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
- format: { with: VALID_EMAIL_REGEX },
- uniqueness: { case_sensitive: false }
- 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 }
+ :format => { with: VALID_EMAIL_REGEX },
+ :uniqueness => { case_sensitive: false }
+ VALID_PHONE_REGEX = /\A\d{3}\d{3}\d{4}\z/
+ validates :phone,
+ :presence => true,
+ :format => { with: VALID_PHONE_REGEX }
+
+ scope :get_all_employers, lambda{Role.find_by(:name => "employer").users.pluck(:name)}
def has_permission? perm
self.permissions.pluck(:name).include? perm
diff --git a/app/views/admin/home/index.html.erb b/app/views/admin/home/index.html.erb
index 1bea26b..07853f1 100644
--- a/app/views/admin/home/index.html.erb
+++ b/app/views/admin/home/index.html.erb
@@ -1,5 +1,5 @@
-
<%= link_to "Create New Editor", new_admin_user_path %>
-<%= link_to "View All Users", user_index_path %>
-<%= link_to "View All Drafted Posts", posts_drafts_path %>
-<%= link_to "View All Published Posts", posts_published_path %>
-<%= link_to "Create new post", new_post_path %>
\ No newline at end of file
+<%= link_to "Create New Editor", "#" %>
+<%= link_to "View All Users", "#" %>
+<%= link_to "View All Drafted Posts", "#" %>
+<%= link_to "View All Published Posts", "#" %>
+<%= link_to "Create new post", "#" %>
diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb
index 591c4b3..2fe494e 100644
--- a/app/views/home/index.html.erb
+++ b/app/views/home/index.html.erb
@@ -1,6 +1,6 @@
<%= link_to "View All Users", user_index_path %>
<%= link_to "View Articles", post_index_path %>
<% if current_user.can_publish? %>
- <%= link_to "View All Drafted Posts", posts_drafts_path %>
+ <%= link_to "View All Drafted Posts", "#" %>
<% end %>
-<%= link_to "Create new post", new_post_path %>
\ No newline at end of file
+<%= link_to "Create new post", "#" %>
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb
index 3500b3e..e134a9a 100644
--- a/app/views/layouts/_header.html.erb
+++ b/app/views/layouts/_header.html.erb
@@ -20,7 +20,7 @@
<% else %>
- <%= link_to "Guest User", post_index_path %>
+ <%= link_to "Guest User", "#" %>
<%= link_to "Sign in", new_user_session_path %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 542fed1..d72eb84 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -10,9 +10,7 @@
resources :user
- get "posts/published", :to => "post#published"
- get "posts/drafts", :to => "post#drafts"
- resources :post do
+ resources :resume do
get :show_post_body
get :publish_draft
end
diff --git a/db/migrate/20140922043613_add_phone_to_user.rb b/db/migrate/20140922043613_add_phone_to_user.rb
new file mode 100644
index 0000000..15b632d
--- /dev/null
+++ b/db/migrate/20140922043613_add_phone_to_user.rb
@@ -0,0 +1,5 @@
+class AddPhoneToUser < ActiveRecord::Migration
+ def change
+ add_column :users, :phone, :integer
+ end
+end
diff --git a/lib/tasks/setup.rake b/lib/tasks/setup.rake
index 752e4ed..ef59ab6 100644
--- a/lib/tasks/setup.rake
+++ b/lib/tasks/setup.rake
@@ -3,18 +3,18 @@ task :setup_sample_application => [:environment] do
puts "Application is being prepared. Please wait."
perm_list = ['application_admin', 'can_publish']
perm_list.each do |p|
- Permission.find_or_create_by_name(p)
+ Permission.find_or_create_by(:name => p)
end
role_list = ["Admin", "Editor", "Reporter"]
role_list.each do |r|
- Role.find_or_create_by_name(r)
+ Role.find_or_create_by(:name => (r))
end
- Role.find_by_name("Admin").permissions << Permission.all
- Role.find_by_name("Editor").permissions << Permission.find_by_name("can_publish")
+ Role.find_by(:name => "Admin").permissions << Permission.all
+ Role.find_by(:name => "Editor").permissions << Permission.find_by(:name => "can_publish")
# Create Dummy Admin User
- user = User.create(:name => "Puneet Goyal", :email => "puneet.goyal@studypadinc.com", :password => "1234567x", :password_confirmation => "1234567x")
- user.roles << Role.find_by_name("Admin")
+ user = User.create!(:name => "Shanil Puri", :email => "shanil.puri@gmail.com", :phone => 9199860912, :password => "1234567x", :password_confirmation => "1234567x")
+ user.roles << Role.find_by(:name => "Admin")
puts "==============> Setup is complete. You may now use the application. :)"
end
\ No newline at end of file