Skip to content

Commit 0ec5460

Browse files
author
Jordan Byron
committed
Add exam admin CRUD
1 parent d393fb6 commit 0ec5460

File tree

15 files changed

+118
-4
lines changed

15 files changed

+118
-4
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
class Admin::ExamsController < Admin::Base
2+
before_filter :find_exam, :only => [:show, :update, :edit, :destroy]
3+
4+
def index
5+
@exams = Exam.all
6+
end
7+
8+
def new
9+
@exam = Exam.new
10+
end
11+
12+
def create
13+
@exam = Exam.new(params[:exam])
14+
15+
if @exam.save
16+
redirect_to admin_exams_path
17+
else
18+
render :action => :new
19+
end
20+
end
21+
22+
def edit
23+
24+
end
25+
26+
def update
27+
if @exam.update_attributes(params[:exam])
28+
redirect_to admin_exams_path
29+
else
30+
render :action => :edit
31+
end
32+
end
33+
34+
def destroy
35+
@exam.destroy
36+
37+
redirect_to admin_exams_path
38+
end
39+
40+
private
41+
42+
def find_exam
43+
@exam = Exam.find(params[:id])
44+
end
45+
end

app/helpers/admin/exams_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module Admin::ExamsHelper
2+
end

app/models/assignment.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class Assignment < ActiveRecord::Base
2-
has_many :submissions, :class_name => "Assignment::Submission"
2+
has_many :submissions, :class_name => "Assignment::Submission",
3+
:dependent => :delete_all
34

45
belongs_to :course
56

app/models/course.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Course < ActiveRecord::Base
22
has_many :course_memberships, :dependent => :destroy
33
has_many :students, :through => :course_memberships
44

5-
has_many :course_instructor_associations
5+
has_many :course_instructor_associations, :dependent => :delete_all
66
has_many :instructors, :through => :course_instructor_associations
77

88
has_many :assignments

app/models/exam.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
class Exam < ActiveRecord::Base
2+
has_many :exam_submissions, :dependent => :delete_all
3+
4+
accepts_nested_attributes_for :exam_submissions
25
end

app/views/admin/_menu.html.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
= link_to "Home", root_path
66
= link_to "Users", admin_users_path
77
= link_to "Courses", admin_courses_path
8+
= link_to "Exams", admin_exams_path
89
|
910
= link_to "Submission Statuses", admin_submission_statuses_path
1011
= render :partial => "users/user_bar"
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
-title 'New Course'
22

3-
43
%h1 New Course
54

6-
- form_for @course, :url => admin_courses_path do |f|
5+
- nested_form_for @course, :url => admin_courses_path do |f|
76
= render :partial => "form", :object => f
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- #TODO: Add start / end time and Hash URL
2+
3+
%p
4+
= f.label :name
5+
%br
6+
= f.text_field :name
7+
%p
8+
= f.submit
9+
= link_to 'Cancel', admin_exams_path
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
%h1 Edit Exam
2+
3+
= form_for @exam, :url => admin_exam_path(@exam) do |f|
4+
= render :partial => "form", :locals => {:f => f}
5+
6+
%table.edit
7+
= f.fields_for :exam_submissions do |e|
8+
%tr
9+
%td= e.object.user.name
10+
%td= e.select :submission_status_id, SubmissionStatus.all.map {|s| [s.name, s.id]}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
%h1 Exams
2+
3+
= button_to "Create Exam", new_admin_exam_path, :method => :get
4+
5+
%table.edit
6+
%thead
7+
%tr
8+
%th Name
9+
%th
10+
%tbody
11+
- @exams.each do |exam|
12+
%tr{:class => cycle('even','odd')}
13+
%td= link_to exam.name, edit_admin_exam_path(exam)
14+
%td= link_to("Destroy", admin_exam_path(exam), :confirm => "Are you sure you wish to delete this exam?", :method => 'DELETE')

0 commit comments

Comments
 (0)