From 30e803d8554aa98f1d22406cca998189f33005d2 Mon Sep 17 00:00:00 2001 From: Gregory Brown Date: Fri, 16 Mar 2012 04:58:56 +0000 Subject: [PATCH 1/7] Initial spike on discussions stub + controller --- app/controllers/discussions_controller.rb | 5 +++++ app/models/discussion.rb | 19 +++++++++++++++++++ config/routes.rb | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 app/controllers/discussions_controller.rb create mode 100644 app/models/discussion.rb diff --git a/app/controllers/discussions_controller.rb b/app/controllers/discussions_controller.rb new file mode 100644 index 0000000..eca7d9d --- /dev/null +++ b/app/controllers/discussions_controller.rb @@ -0,0 +1,5 @@ +class DiscussionsController < ApplicationController + def index + render :text => Discussion.reviews + end +end diff --git a/app/models/discussion.rb b/app/models/discussion.rb new file mode 100644 index 0000000..e625d6e --- /dev/null +++ b/app/models/discussion.rb @@ -0,0 +1,19 @@ +class Discussion + def self.conversations + [ "How awesome is Jordan Byron?", + "How many unicorns does it take to make a rainbow?", + "Can someone ask a serious question please?" ] + end + + def self.evaluations + [ "My s10-e2 is ready for evaluation", + "Revisions have been made to my s10-e1", + "Come on, evaluate it, you know you want to!" ] + end + + def self.reviews + ["Messy first spike on my individual project", + "Proof of concept patch to add archives to Newman", + "If you don't review this soon, I might go crazy!"] + end +end diff --git a/config/routes.rb b/config/routes.rb index 769e68d..b2972af 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,5 +5,7 @@ match '/auth/failure' => 'sessions#failure' match '/logout' => 'sessions#destroy', as: 'logout' - resources :courses + resources :courses do + resources :discussions + end end From eb68e5cf4f12486c58355dd85dd1b36264bb1721 Mon Sep 17 00:00:00 2001 From: Gregory Brown Date: Fri, 16 Mar 2012 05:29:54 +0000 Subject: [PATCH 2/7] Basic filtering of discussion listing --- app/controllers/discussions_controller.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/controllers/discussions_controller.rb b/app/controllers/discussions_controller.rb index eca7d9d..c2732d0 100644 --- a/app/controllers/discussions_controller.rb +++ b/app/controllers/discussions_controller.rb @@ -1,5 +1,20 @@ class DiscussionsController < ApplicationController + before_filter :find_course + def index - render :text => Discussion.reviews + @discussions = case params[:type] + when "conversation" + Discussion.conversations + when "review" + Discussion.reviews + when "evaluation" + Discussion.evaluations + else + Discussion.conversations + end + end + + def find_course + @course = Course.find(params[:course_id]) end end From ccafde0a53e35baf15c1e2d239a5b064f67d8dcb Mon Sep 17 00:00:00 2001 From: Gregory Brown Date: Fri, 16 Mar 2012 05:31:58 +0000 Subject: [PATCH 3/7] add missing index file --- app/views/discussions/index.html.haml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 app/views/discussions/index.html.haml diff --git a/app/views/discussions/index.html.haml b/app/views/discussions/index.html.haml new file mode 100644 index 0000000..62468f7 --- /dev/null +++ b/app/views/discussions/index.html.haml @@ -0,0 +1,11 @@ += link_to "Conversations", course_discussions_path(:type => "conversation") +| += link_to "Reviews", course_discussions_path(:type => "review") +| += link_to "Evaluations", course_discussions_path(:type => "evaluation") + +%br +%br + +- @discussions.each do |r| + %h3= r From 744bf497dfb82d57dc84015ff7d264414918302d Mon Sep 17 00:00:00 2001 From: Gregory Brown Date: Fri, 16 Mar 2012 05:54:49 +0000 Subject: [PATCH 4/7] Convert discussion to be AR-backed --- app/models/course.rb | 1 + app/models/discussion.rb | 20 +++++------ app/views/discussions/index.html.haml | 4 +-- .../20120316053737_create_discussions.rb | 14 ++++++++ db/schema.rb | 11 +++++- db/seeds.rb | 35 ++++++++++++++++++- 6 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20120316053737_create_discussions.rb diff --git a/app/models/course.rb b/app/models/course.rb index 7a22383..331226c 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,2 +1,3 @@ class Course < ActiveRecord::Base + has_many :discussions end diff --git a/app/models/discussion.rb b/app/models/discussion.rb index e625d6e..6a1f6f4 100644 --- a/app/models/discussion.rb +++ b/app/models/discussion.rb @@ -1,19 +1,15 @@ -class Discussion +class Discussion < ActiveRecord::Base + belongs_to :course + def self.conversations - [ "How awesome is Jordan Byron?", - "How many unicorns does it take to make a rainbow?", - "Can someone ask a serious question please?" ] + where(:category => "conversation") end - def self.evaluations - [ "My s10-e2 is ready for evaluation", - "Revisions have been made to my s10-e1", - "Come on, evaluate it, you know you want to!" ] + def self.reviews + where(:category => "review") end - def self.reviews - ["Messy first spike on my individual project", - "Proof of concept patch to add archives to Newman", - "If you don't review this soon, I might go crazy!"] + def self.evaluations + where(:category => "evaluation") end end diff --git a/app/views/discussions/index.html.haml b/app/views/discussions/index.html.haml index 62468f7..3ee95d4 100644 --- a/app/views/discussions/index.html.haml +++ b/app/views/discussions/index.html.haml @@ -7,5 +7,5 @@ %br %br -- @discussions.each do |r| - %h3= r +- @discussions.each do |discussion| + %h3= discussion.subject diff --git a/db/migrate/20120316053737_create_discussions.rb b/db/migrate/20120316053737_create_discussions.rb new file mode 100644 index 0000000..ff80160 --- /dev/null +++ b/db/migrate/20120316053737_create_discussions.rb @@ -0,0 +1,14 @@ +class CreateDiscussions < ActiveRecord::Migration + def change + create_table :discussions do |t| + t.string :category + + t.text :subject + t.text :body + + t.belongs_to :course + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 805ff83..8758ef1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120311191726) do +ActiveRecord::Schema.define(:version => 20120316053737) do create_table "courses", :force => true do |t| t.string "name" @@ -20,4 +20,13 @@ t.datetime "updated_at", :null => false end + create_table "discussions", :force => true do |t| + t.string "category" + t.text "subject" + t.text "body" + t.integer "course_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + end diff --git a/db/seeds.rb b/db/seeds.rb index 4ec73dd..4b11e21 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1 +1,34 @@ -Course.find_or_create_by_name(name: "Web Development", description: "# Welcome to Web Dev 3.0!") \ No newline at end of file +course = Course.find_or_create_by_name(name: "Web Development", + description: "# Welcome to Web Dev 3.0!") + + +conversations = [ "How awesome is Jordan Byron?", + "How many unicorns does it take to make a rainbow?", + "Can someone ask a serious question please?" ] + +conversations.each do |e| + course.discussions.find_or_create_by_subject( + :subject => e, :category => "conversation" + ) +end + +evaluations = [ "My s10-e2 is ready for evaluation", + "Revisions have been made to my s10-e1", + "Come on, evaluate it, you know you want to!" ] + +evaluations.each do |e| + course.discussions.find_or_create_by_subject( + :subject => e, :category => "evaluation" + ) +end + +reviews = ["Messy first spike on my individual project", + "Proof of concept patch to add archives to Newman", + "If you don't review this soon, I might go crazy!"] + +reviews.each do |e| + course.discussions.find_or_create_by_subject( + :subject => e, :category => "review" + ) +end + From 198f86923c3d77d50eea0e84bbcded1c41fafd51 Mon Sep 17 00:00:00 2001 From: Gregory Brown Date: Fri, 16 Mar 2012 06:03:09 +0000 Subject: [PATCH 5/7] Use category rather than type throughout --- app/controllers/discussions_controller.rb | 2 +- app/views/discussions/index.html.haml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/discussions_controller.rb b/app/controllers/discussions_controller.rb index c2732d0..be4aad4 100644 --- a/app/controllers/discussions_controller.rb +++ b/app/controllers/discussions_controller.rb @@ -2,7 +2,7 @@ class DiscussionsController < ApplicationController before_filter :find_course def index - @discussions = case params[:type] + @discussions = case params[:category] when "conversation" Discussion.conversations when "review" diff --git a/app/views/discussions/index.html.haml b/app/views/discussions/index.html.haml index 3ee95d4..db7033b 100644 --- a/app/views/discussions/index.html.haml +++ b/app/views/discussions/index.html.haml @@ -1,8 +1,8 @@ -= link_to "Conversations", course_discussions_path(:type => "conversation") += link_to "Conversations", course_discussions_path(:category => "conversation") | -= link_to "Reviews", course_discussions_path(:type => "review") += link_to "Reviews", course_discussions_path(:category => "review") | -= link_to "Evaluations", course_discussions_path(:type => "evaluation") += link_to "Evaluations", course_discussions_path(:category => "evaluation") %br %br From 05cb770c667aed802793e75d108736830a69e995 Mon Sep 17 00:00:00 2001 From: Jia Wu Date: Fri, 16 Mar 2012 12:39:38 -0400 Subject: [PATCH 6/7] limit discussions to a particular course --- app/controllers/discussions_controller.rb | 8 ++++---- db/schema.rb | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/discussions_controller.rb b/app/controllers/discussions_controller.rb index be4aad4..84045a5 100644 --- a/app/controllers/discussions_controller.rb +++ b/app/controllers/discussions_controller.rb @@ -4,13 +4,13 @@ class DiscussionsController < ApplicationController def index @discussions = case params[:category] when "conversation" - Discussion.conversations + @course.discussions.conversations when "review" - Discussion.reviews + @course.discussions.reviews when "evaluation" - Discussion.evaluations + @course.discussions.evaluations else - Discussion.conversations + @course.discussions.conversations end end diff --git a/db/schema.rb b/db/schema.rb index 8758ef1..dbb8f64 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -13,6 +13,14 @@ ActiveRecord::Schema.define(:version => 20120316053737) do + create_table "course_memberships", :force => true do |t| + t.integer "course_id" + t.string "person_github_nickname" + t.string "role" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "courses", :force => true do |t| t.string "name" t.text "description" From 5c92cb434c7471c03cfa2e8851ad1ec253d2f452 Mon Sep 17 00:00:00 2001 From: Jia Wu Date: Fri, 16 Mar 2012 12:41:23 -0400 Subject: [PATCH 7/7] make find_course private --- app/controllers/discussions_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/discussions_controller.rb b/app/controllers/discussions_controller.rb index 84045a5..63c7510 100644 --- a/app/controllers/discussions_controller.rb +++ b/app/controllers/discussions_controller.rb @@ -14,6 +14,8 @@ def index end end + private + def find_course @course = Course.find(params[:course_id]) end