From 269e95209220c74894b02c3beb1a44ce8782397c Mon Sep 17 00:00:00 2001 From: Shanil Puri Date: Fri, 26 Sep 2014 23:51:02 -0400 Subject: [PATCH] Addint left over functionality --- app/controllers/admin/users_controller.rb | 10 ++++-- app/controllers/job_controller.rb | 13 ++++++++ app/controllers/sessions_controller.rb | 4 --- app/views/job/_jobs_table.html.erb | 40 +++++++++++++++++++++++ app/views/job/index.html.erb | 40 +---------------------- app/views/job/my_jobs.html.erb | 8 +++++ app/views/job/show.html.erb | 8 +++-- config/routes.rb | 3 +- 8 files changed, 77 insertions(+), 49 deletions(-) create mode 100644 app/views/job/_jobs_table.html.erb create mode 100644 app/views/job/my_jobs.html.erb diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 7e9cbde..445cbdc 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -22,12 +22,18 @@ def create private def update_new_user user, new_user_hash + role_hash = new_user_hash["role"] + new_user_hash = new_user_hash.slice!("role") + puts "##############################################################################################################\n" puts new_user_hash + puts "##############################################################################################################" user.update_attributes(new_user_hash) + + if user.errors.blank? user.save! - # user.roles << Role.find(assigned_role[:id]) + user.roles << Role.find(role_hash[:id]) else @errors = user.errors.full_messages @errors.each do |e| @@ -38,7 +44,7 @@ def update_new_user user, new_user_hash end def user_params - params.require(:user).permit(:name, :phone, :email, :password, :password_confirmation, {:role => [:id, :name]}) + params.require(:user).permit(:name, :phone, :email, :password, :password_confirmation, {:role => [:id, :role]}) end # def role_params diff --git a/app/controllers/job_controller.rb b/app/controllers/job_controller.rb index 0cf84a0..f31b700 100644 --- a/app/controllers/job_controller.rb +++ b/app/controllers/job_controller.rb @@ -16,6 +16,19 @@ def show @job = Job.find(params[:id]) end + def my_jobs + if current_user.is_employer? + @jobs = Job.where(:owner_id => current_user.id) + puts @jobs + elsif current_user.is_jobseeker? + @jobs = current_user.jobs + else + puts"this should be called" + flash[:notice] = "You are the ADMIN. Please remember: With great power comes great responsibility :)" + @jobs = Job.all + end + end + def create job = Job.new diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 401fe70..3becc99 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,10 +1,6 @@ class SessionsController < Devise::SessionsController def after_sign_in_path_for(resource) - puts "#################\n\n" - puts resource if resource.is_a?(User) - puts "#################" - puts "this should be called" resource.is_admin? ? admin_home_index_path : root_path else super diff --git a/app/views/job/_jobs_table.html.erb b/app/views/job/_jobs_table.html.erb new file mode 100644 index 0000000..a664a8e --- /dev/null +++ b/app/views/job/_jobs_table.html.erb @@ -0,0 +1,40 @@ +*Click on Jobs to view details +
+ + + + + + + + + + <% @jobs.each do |job| %> + + + + + + <% end %> + +
Owner NameJob TitleApplication Deadline
<%= User.find(job.owner_id).name %><%= link_to job.title, job_path(:id => job.id), :class => "job_body_link" %>
+
+ + \ No newline at end of file diff --git a/app/views/job/index.html.erb b/app/views/job/index.html.erb index d5f1e12..b1ed999 100644 --- a/app/views/job/index.html.erb +++ b/app/views/job/index.html.erb @@ -3,44 +3,6 @@ <% if can_post_new_job? %> <%= link_to "Post New Job", new_job_path %> <% end %> - *Click on Job to apply - -
- - - - - - - - - - <% @jobs.each do |job| %> - - - - - - <% end %> - -
Owner NameJob TitleApplication Deadline
<%= User.find(job.owner_id).name %><%= link_to job.title, job_path(:id => job.id), :class => "job_body_link" %>
- \ No newline at end of file +<%= render :partial => "jobs_table.html.erb" %> \ No newline at end of file diff --git a/app/views/job/my_jobs.html.erb b/app/views/job/my_jobs.html.erb new file mode 100644 index 0000000..baa21e1 --- /dev/null +++ b/app/views/job/my_jobs.html.erb @@ -0,0 +1,8 @@ +
+

My Jobs

+ <% if can_post_new_job? %> + <%= link_to "Post New Job", new_job_path %> + <% end %> +
+ +<%= render :partial => "jobs_table.html.erb" %> \ No newline at end of file diff --git a/app/views/job/show.html.erb b/app/views/job/show.html.erb index f692efd..389f5b9 100644 --- a/app/views/job/show.html.erb +++ b/app/views/job/show.html.erb @@ -10,6 +10,8 @@
<%= @job.deadline %>
-
- <%= link_to "Apply", job_apply_path(:job_id=>@job.id), :confirm => "Your profile information will be used for this job application. Are you sure you wish to proceed?" %> -
\ No newline at end of file +<% if current_user.is_jobseeker? %> +
+ <%= link_to "Apply", job_apply_path(:job_id=>@job.id), :confirm => "Your profile information will be used for this job application. Are you sure you wish to proceed?" %> +
+<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1c610f4..5d4dedc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,12 +2,13 @@ devise_for :users, :controllers => {:registrations => "registrations", :sessions=>"sessions"} root :to => "home#index" - resources :job do + get "/my_jobs" => :my_jobs, :on => :collection get :autocomplete_category_name, :on => :collection get "/apply" => :apply end + namespace :admin do resources :home , :only => [:index] resources :users do