Class: JobsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/jobs_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#robot?

Instance Method Details

#assignmentsObject


65
66
67
68
69
# File 'app/controllers/jobs_controller.rb', line 65

def assignments
  authorize! :see_job_details, Job
  @jobs = Job.active
  @all_employees = Job.all_employees
end

#createObject

POST /jobs


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/jobs_controller.rb', line 28

def create
  authorize! :create, Job
  params[:job][:supervisors_override] = params[:supervisors]
  params[:job][:employees_override] = params[:students]
  @job = Job.new(params[:job])
  @projects = SponsoredProject.current

  respond_to do |format|
    if @job.save
      format.html { redirect_to(jobs_path, :notice => 'Job was successfully created.') }
    else
      format.html { render :action => "new" }
    end
  end
end

#editObject

GET /jobs/1/edit


21
22
23
24
25
# File 'app/controllers/jobs_controller.rb', line 21

def edit
  @job = Job.find(params[:id])
  authorize! :update, @job
  @projects = SponsoredProject.current
end

#indexObject

GET /jobs


7
8
9
10
# File 'app/controllers/jobs_controller.rb', line 7

def index
  @jobs = Job.scoped
  @jobs = @jobs.active if params[:show_all] != "true"
end

#newObject

GET /jobs/new


13
14
15
16
17
18
# File 'app/controllers/jobs_controller.rb', line 13

def new
  authorize! :create, Job
  @job = Job.new
  @job.supervisors << current_user
  @projects = SponsoredProject.current
end

#updateObject

PUT /jobs/1 PUT /jobs/1.xml


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/jobs_controller.rb', line 46

def update
  params[:job][:supervisors_override] = params[:supervisors]
  params[:job][:employees_override] = params[:students]
  @job = Job.find(params[:id])
  authorize! :update, @job
  if  params[:job][:is_closed].present? && params[:job][:is_closed] == "true"
    notice_msg = "Job was closed."
  end
  @projects = SponsoredProject.current

  respond_to do |format|
    if @job.update_attributes(params[:job])
      format.html { redirect_to(jobs_path, :notice => notice_msg || 'Job was successfully updated.') }
    else
      format.html { render :action => "edit" }
    end
  end
end