Class: AssignmentsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#robot?

Instance Method Details

#createObject

POST /assignments POST /assignments.xml


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

def create
  @assignment = @course.assignments.new(params[:assignment])
  authorize! :update, @course
  @assignment.set_due_date(params[:due_date][:date], params[:due_date][:hour], params[:due_date][:minute]) if params.has_key?(:due_date)
  respond_to do |format|
    if @assignment.save
      format.html { redirect_to(course_assignments_path, :notice => "#{@wording}  #{@assignment.name} was successfully created.") }
      format.xml { render :xml => @assignment, :status => :created, :location => @assignment }
    else
      format.html { render :action => "new" }
      format.xml { render :xml => @assignment.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /assignments/1 DELETE /assignments/1.xml


103
104
105
106
107
108
109
110
111
# File 'app/controllers/assignments_controller.rb', line 103

def destroy
  @assignment = Assignment.find(params[:id])
  authorize! :destroy, @assignment

  @assignment.destroy
  respond_to do |format|
    format.js
  end
end

#editObject

GET /assignments/1/edit


42
43
44
45
# File 'app/controllers/assignments_controller.rb', line 42

def edit
  @assignment = Assignment.find(params[:id])
  authorize! :update, @course
end

#get_courseObject


10
11
12
13
# File 'app/controllers/assignments_controller.rb', line 10

def get_course
  @course=Course.find(params[:course_id])
  @wording = @course.nomenclature_assignment_or_deliverable
end

#indexObject


19
20
21
22
23
24
25
26
27
# File 'app/controllers/assignments_controller.rb', line 19

def index
  @assignments = Assignment.all(:conditions => ["course_id = ?", @course.id])
  authorize! :read, Assignment

  respond_to do |format|
    format.html # index.html.erb
    format.xml { render :xml => @assignments }
  end
end

#newObject

GET /assignments/new GET /assignments/new.xml


31
32
33
34
35
36
37
38
39
# File 'app/controllers/assignments_controller.rb', line 31

def new
  @assignment = Assignment.new
  authorize! :update, @course

  respond_to do |format|
    format.html # new.html.erb
    format.xml { render :xml => @assignment }
  end
end

#render_grade_book_menuObject


15
16
17
# File 'app/controllers/assignments_controller.rb', line 15

def render_grade_book_menu
  @is_in_grade_book = true
end

#repositionObject

Inspiration for this technique comes from two sources A: awesomeful.net/posts/47-sortable-lists-with-jquery-in-rails (yield javascript, jquery ui code) B: henrik.nyh.se/2008/11/rails-jquery-sortables#comment-17220662 (model update code)


129
130
131
132
133
134
135
136
# File 'app/controllers/assignments_controller.rb', line 129

def reposition
  authorize! :reorder_assignments, @course

  order = params[:assignment]
  Rails.logger.debug(order)
  Assignment.reposition(order)
  render :text => order.inspect
end

#showObject

GET /course/assignment_reorder/1


115
116
117
118
119
120
121
122
123
# File 'app/controllers/assignments_controller.rb', line 115

def show
  @no_pad = true
  @assignments = @course.assignments
  authorize! :read, @course

  respond_to do |format|
    format.html # showml.erb
  end
end

#updateObject

PUT /assignments/1 PUT /assignments/1.xml


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/controllers/assignments_controller.rb', line 66

def update
  @assignment = Assignment.find(params[:id])
  authorize! :update, @course

  @assignment.set_due_date(params[:due_date][:date], params[:due_date][:hour], params[:due_date][:minute]) if params.has_key?(:due_date)
  =Deliverable.find_all_by_assignment_id(@assignment.id).first
  deliverable_status=0;
  unless .nil?
    if @assignment.is_team_deliverable.to_s!= params[:assignment]["is_team_deliverable"]
      deliverable_status=1
      flash[:error] = "You cannot change the Type as the student(s) has already submitted for this item."

    end
  end

  if deliverable_status==0
    respond_to do |format|
      if @assignment.update_attributes(params[:assignment])
        format.html { redirect_to(course_assignments_path, :notice => "Assignment #{@assignment.name} was successfully updated.") }
        format.xml { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml { render :xml => @assignment.errors, :status => :unprocessable_entity }
      end
    end
  else
    respond_to do |format|
      format.html { render :action => "edit" }
      format.xml { render :xml => @assignment.errors, :status => :unprocessable_entity }
    end
  end


end