Browse files

Changed database to match new model structure for grades and exams

  • Loading branch information...
1 parent 17abbf2 commit 8450256bc296db41cc970774630d712754cf67f9 @gorrillamcd committed Jun 4, 2012
View
3 app/assets/javascripts/exams.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3 app/assets/stylesheets/exams.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the exams controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
15 app/controllers/exams_controller.rb
@@ -0,0 +1,15 @@
+class ExamsController < ApplicationController
+
+ def show
+
+ end
+
+ def new
+
+ end
+
+ def create
+
+ end
+
+end
View
8 app/controllers/lessons_controller.rb
@@ -10,8 +10,8 @@ def create
@course = Course.find(params[:course_id])
@lesson = @course.lessons.create(params[:lesson])
if @lesson.save
- redirect_to course_path(@course)
- flash[:success] = "Successfully created lesson."
+ redirect_to exam_path(@lesson)
+ flash[:notice] = "Successfully created lesson."
else
render :action => 'new', :error => "Something went wrong."
end
@@ -27,9 +27,9 @@ def update
@lesson = @course.lessons.find(params[:id])
if @lesson.update_attributes(params[:lesson])
redirect_to course_lesson_path(@course, @lesson)
- flash[:success] = "Successfully updated course."
+ flash[:notice] = "Successfully updated course."
else
- render :action => 'edit'
+ render :action => 'edit', :error => "Something went wrong."
end
end
View
2 app/controllers/questions_controller.rb
@@ -1,2 +0,0 @@
-class QuestionsController < ApplicationController
-end
View
2 app/controllers/registrations_controller.rb
@@ -6,6 +6,8 @@ def new
def create
# Make something like this for assigning user.role
+ # P.S. I know now this is wrong and I should use if statements instead. But I'll leave this here to remind me it needs to be done.
+ #
# case params[role]
# when params[role] == "admin" && @user.can?.update_attribute
# @user.role = params[role]
View
2 app/helpers/exams_helper.rb
@@ -0,0 +1,2 @@
+module ExamsHelper
+end
View
4 app/models/answer.rb
@@ -1,3 +1,7 @@
class Answer < ActiveRecord::Base
+
+ attr_accessible :text, :question_id, :correct # TODO: Take :correct off attr_accessible and assign properly
+
belongs_to :question
+
end
View
12 app/models/exam.rb
@@ -0,0 +1,12 @@
+class Exam < ActiveRecord::Base
+ # Exam is the model that contains the exams themselves. It's accompanying controller is for administrating exams. If you want the functionality for a student "taking" exams, check out Grade and grades_controller.
+
+ attr_accessible :type, :questions_attributes
+
+ belongs_to :lesson
+ has_one :grade
+ has_many :questions
+
+ accepts_nested_attributes_for :questions, :allow_destroy => true
+
+end
View
5 app/models/grade.rb
@@ -1,4 +1,7 @@
class Grade < ActiveRecord::Base
belongs_to :subscription
- belongs_to :lesson
+ belongs_to :exam
+
+ ## Grading Methods ##
+
end
View
3 app/models/lesson.rb
@@ -2,8 +2,7 @@ class Lesson < ActiveRecord::Base
attr_accessible :name, :description, :teaching
belongs_to :course
- has_many :questions
- has_many :grades
+ has_one :exam
has_attached_file :teaching
View
6 app/models/question.rb
@@ -1,6 +1,8 @@
class Question < ActiveRecord::Base
- belongs_to :lesson
+ attr_accessible :text, :exam_id, :answers_attributes
+
+ belongs_to :exam
has_many :answers
- accepts_nested_attributes_for :answers, :allow_destroy => :true, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
+ accepts_nested_attributes_for :answers, :allow_destroy => :true
end
View
8 app/models/user.rb
@@ -33,4 +33,12 @@ def has_courses?
end
end
+ def is_admin?(user)
+ if user.role == 'admin'
+ return true
+ else
+ return false
+ end
+ end
+
end
View
2 app/views/lessons/_form.html.erb
@@ -6,7 +6,7 @@
<%= f.input :teaching, :as => :file %>
<div class="form-actions">
- <%= f.submit nil, :class => "btn btn-primary" %>
+ <%= f.submit "Next Step", :class => "btn btn-primary" %>
<%= link_to "Cancel", @course, :class=>"btn" %>
</div>
</fieldset>
View
10 config/routes.rb
@@ -17,8 +17,14 @@
resources :books
end
- resources :subscriptions, :only => [:create, :update]
+ resources :lessons do
+ resources :exams
+ end
- resources :questions
+ resources :exams do
+ resources :grades
+ end
+
+ resources :subscriptions, :only => [:create, :update]
end
View
13 db/migrate/20120528223348_remove_examid_from_question.rb
@@ -1,13 +0,0 @@
-class RemoveExamidFromQuestion < ActiveRecord::Migration
-
- def up
- remove_index :questions, :exam_id
- remove_column :questions, :exam_id
- end
-
- def down
- add_column :questions, :exam_id, :integer
- add_index :questions, :exam_id
- end
-
-end
View
7 db/migrate/20120408233738_create_exams.rb → db/migrate/20120529212319_create_exams.rb
@@ -1,11 +1,12 @@
class CreateExams < ActiveRecord::Migration
def change
create_table :exams do |t|
- t.string :name
- t.references :course
+ t.string :type
+ t.integer :weight
+ t.references :lesson
t.timestamps
end
- add_index :exams, :course_id
+ add_index :exams, :lesson_id
end
end
View
6 db/migrate/20120601181528_remove_lessonid_from_question.rb
@@ -0,0 +1,6 @@
+class RemoveLessonidFromQuestion < ActiveRecord::Migration
+ def change
+ remove_index :questions, :lesson_id
+ remove_column :questions, :lesson_id
+ end
+end
View
8 db/migrate/20120604184233_remove_lessonid_from_grades.rb
@@ -0,0 +1,8 @@
+class RemoveLessonidFromGrades < ActiveRecord::Migration
+ def change
+ remove_index :grades, :lesson_id
+ remove_column :grades, :lesson_id
+ add_column :grades, :exam_id, :integer
+ add_index :grades, :exam_id
+ end
+end
View
20 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120528223348) do
+ActiveRecord::Schema.define(:version => 20120604184233) do
create_table "answers", :force => true do |t|
t.string "text"
@@ -44,15 +44,25 @@
t.integer "credits"
end
+ create_table "exams", :force => true do |t|
+ t.string "type"
+ t.integer "weight"
+ t.integer "lesson_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "exams", ["lesson_id"], :name => "index_exams_on_lesson_id"
+
create_table "grades", :force => true do |t|
t.integer "average_grade"
t.integer "subscription_id"
- t.integer "lesson_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.integer "exam_id"
end
- add_index "grades", ["lesson_id"], :name => "index_grades_on_lesson_id"
+ add_index "grades", ["exam_id"], :name => "index_grades_on_exam_id"
add_index "grades", ["subscription_id"], :name => "index_grades_on_subscription_id"
create_table "lessons", :force => true do |t|
@@ -71,12 +81,12 @@
create_table "questions", :force => true do |t|
t.string "text"
- t.integer "lesson_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.integer "exam_id"
end
- add_index "questions", ["lesson_id"], :name => "index_questions_on_lesson_id"
+ add_index "questions", ["exam_id"], :name => "index_questions_on_exam_id"
create_table "subscriptions", :force => true do |t|
t.integer "course_id"
View
5 spec/controllers/exams_controller_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe ExamsController do
+
+end
View
9 spec/factories/exams.rb
@@ -0,0 +1,9 @@
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :exam do
+ type ""
+ weight 1
+ lesson nil
+ end
+end
View
15 spec/helpers/exams_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the ExamsHelper. For example:
+#
+# describe ExamsHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe ExamsHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/models/exam_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Exam do
+ pending "add some examples to (or delete) #{__FILE__}"
+end

0 comments on commit 8450256

Please sign in to comment.