Skip to content

Commit

Permalink
Pointing links to # and updated routes and controllers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shanil Puri committed Sep 23, 2014
1 parent c196fcf commit f987037
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 44 deletions.
4 changes: 3 additions & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class HomeController < ApplicationController
def index

if current_user.is_employer
redirect_to employer_home_path
end
end
end
45 changes: 14 additions & 31 deletions app/controllers/resume_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,41 @@ class ResumeController < ApplicationController
skip_before_filter :authenticate_user!, :only => [:index, :show]

def index
@posts = current_user ? (current_user.is_admin? ? Post.all : (Post.published + current_user.posts)) : Post.published
@resume = current_user.resume
end

def new
@post = Post.new
@resume = Resume.new
end

def create
post = Post.new
resume = Resume.new
@errors = []
ActiveRecord::Base.transaction do
update_new_post post, params["resume"]
update_new_resume resume, params["resume"]
end
redirect_to create_redirector_path if @errors.blank?
end


def published
@posts = Post.published
end

def drafts
@posts = Post.drafts
end

def publish_draft
post = Post.find(params["post_id"].to_i)
post.draft = false
post.save!
flash[:success] = "The article has been successfully published."
redirect_to posts_drafts_path
end

def show
post = Post.find(params["id"].to_i)
render :partial => "show_post", :locals => {:resume => post}
resume = Resume.find(params["id"].to_i)
render :partial => "show_resume", :locals => {:resume => resume}
end

private

def update_new_post post, new_post_hash
post.update_attributes(new_post_hash)
if post.errors.blank?
post.owner_id = current_user.id
current_user.can_publish? ? (post.draft = false) : (post.draft = true)
post.save!
def update_new_resume resume, new_resume_hash
Resume.update_attributes(new_resume_hash)
if Resume.errors.blank?
Resume.owner_id = current_user.id
current_user.can_publish? ? (Resume.draft = false) : (Resume.draft = true)
Resume.save!
else
@errors = post.errors.full_messages
@errors = Resume.errors.full_messages
@errors.each do |e|
flash[:error] = e
end
redirect_to new_post_path
redirect_to new_resume_path
end
end
end
2 changes: 1 addition & 1 deletion app/models/role.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Role < ActiveRecord::Base
has_many :users
has_and_belongs_to_many :users
has_and_belongs_to_many :permissions
end
25 changes: 18 additions & 7 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ class User < ActiveRecord::Base
: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
end
scope :get_all_employers, lambda{Role.find_by(:name => "Employer").users.pluck(:name)}
scope :get_all_jobseekers, lambda{Role.find_by(:name => "Jobseeker").users.pluck(:name)}

def has_role? role
self.roles.include? role
Expand All @@ -37,7 +34,21 @@ def is_admin?
self.has_permission? "application_admin"
end

def can_post?
self.has_permission? "can_post"
def can_publish?
self.has_permission? "can_publish"
end

def can_apply_to_job?
self.has_permission? "can_apply"
end

private

##
# Function: Checks the permissions of the user against the requested permissions
# Returns: TRUE if permission exists else FALSE
##
def has_permission? perm
self.permissions.pluck(:name).include? perm
end
end
2 changes: 1 addition & 1 deletion app/views/admin/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<div><%= link_to "View All Users", "#" %></div>
<div><%= link_to "View All Drafted Posts", "#" %></div>
<div><%= link_to "View All Published Posts", "#" %></div>
<div><%= link_to "Create new post", "#" %></div>
<div><%= link_to "Create new resume", "#" %></div>
4 changes: 2 additions & 2 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div><%= link_to "View All Users", user_index_path %></div>
<div><%= link_to "View Articles", post_index_path %></div>
<div><%= link_to "View Articles", "#" %></div>
<% if current_user.can_publish? %>
<div><%= link_to "View All Drafted Posts", "#" %></div>
<% end %>
<div><%= link_to "Create new post", "#" %></div>
<div><%= link_to "Create new resume", "#" %></div>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# resources :products do
# member do
# get 'short'
# post 'toggle'
# resume 'toggle'
# end
#
# collection do
Expand Down

0 comments on commit f987037

Please sign in to comment.