Created
February 25, 2015 15:04
-
-
Save kalabiyau/42ddee23a5c97b57aba7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git c/Gemfile i/Gemfile | |
index b283467..615a439 100644 | |
--- c/Gemfile | |
+++ i/Gemfile | |
@@ -39,6 +39,7 @@ group :development, :test do | |
# Use sqlite3 as the database for Active Record | |
gem 'sqlite3' | |
gem 'pry-rails' | |
+ gem 'awesome_print' | |
end | |
group :test do | |
diff --git c/Gemfile.lock i/Gemfile.lock | |
index 0cdb665..3116782 100644 | |
--- c/Gemfile.lock | |
+++ i/Gemfile.lock | |
@@ -49,6 +49,7 @@ GEM | |
tzinfo (~> 1.1) | |
addressable (2.3.6) | |
arel (6.0.0) | |
+ awesome_print (1.6.1) | |
binding_of_caller (0.7.2) | |
debug_inspector (>= 0.0.1) | |
builder (3.2.2) | |
@@ -265,6 +266,7 @@ PLATFORMS | |
ruby | |
DEPENDENCIES | |
+ awesome_print | |
byebug | |
capybara | |
coffee-rails (~> 4.1.0) | |
diff --git c/app/controllers/comments_controller.rb i/app/controllers/comments_controller.rb | |
new file mode 100644 | |
index 0000000..a93e11b | |
--- /dev/null | |
+++ i/app/controllers/comments_controller.rb | |
@@ -0,0 +1,29 @@ | |
+require 'awesome_print' | |
+ | |
+class CommentsController < ApplicationController | |
+ | |
+ def index | |
+ @comment = Comment.new | |
+ end | |
+ | |
+ def create | |
+ @activity = Activity.find(params[:activity_id]) | |
+ @comment = Comment.new(permitted_params) | |
+ @comment.activity = @activity | |
+ if @comment.save | |
+ flash[:notice] = 'Comment Added' | |
+ redirect_to activities_url | |
+ else | |
+ flash[:alert] = 'Comment Cannot be Added' | |
+ render :index | |
+ end | |
+ end | |
+ | |
+ protected | |
+ | |
+ def permitted_params | |
+ params.require(:comment).permit(:content, :mood, :fun_level) | |
+ | |
+ end | |
+ | |
+end | |
diff --git c/app/models/activity.rb i/app/models/activity.rb | |
index c803820..f397b80 100644 | |
--- c/app/models/activity.rb | |
+++ i/app/models/activity.rb | |
@@ -1,6 +1,9 @@ | |
class Activity < ActiveRecord::Base | |
+ | |
has_and_belongs_to_many :users | |
has_one :creator, class_name: User | |
+ has_many :comments | |
+ | |
validates :name, presence: true | |
validates :name, uniqueness: true | |
end | |
diff --git c/app/models/comment.rb i/app/models/comment.rb | |
new file mode 100644 | |
index 0000000..dbfbbfd | |
--- /dev/null | |
+++ i/app/models/comment.rb | |
@@ -0,0 +1,3 @@ | |
+class Comment < ActiveRecord::Base | |
+ belongs_to :activity | |
+end | |
diff --git c/app/views/activities/index.html.slim i/app/views/activities/index.html.slim | |
index 6dbe930..357999a 100644 | |
--- c/app/views/activities/index.html.slim | |
+++ i/app/views/activities/index.html.slim | |
@@ -11,5 +11,14 @@ | |
= link_to 'destroy', activity_path(a), method: :delete | |
.join | |
= link_to 'join', join_activity_url(a.id), method: :post | |
+ - if a.comments.any? | |
+ h4 Comments: | |
+ | |
+ ul | |
+ - a.comments.each do |comment| | |
+ li | |
+ div Text | |
+ div | |
+ = comment.content | |
= link_to 'New', new_activity_path | |
diff --git c/app/views/comments/index.html.slim i/app/views/comments/index.html.slim | |
new file mode 100644 | |
index 0000000..66b601f | |
--- /dev/null | |
+++ i/app/views/comments/index.html.slim | |
@@ -0,0 +1,18 @@ | |
+.row | |
+ .col-md-4 | |
+ = form_for [:activity, @comment], html: { class: 'form-horizontal' }do |f| | |
+ .form-group | |
+ = f.label :content | |
+ = f.text_field :content, class: 'form-control' | |
+ .form-group | |
+ | |
+ .checkbox | |
+ = f.label :hide_it do | |
+ = f.check_box :hide_it | |
+ | Hide me | |
+ .form-group | |
+ = f.label :fun_level | |
+ = f.select :fun_level, %w{ crazy funny funky destroyed }, {}, class: 'form-control' | |
+ .submit | |
+ = f.submit 'Save', class: 'btn btn-default' | |
+ | |
diff --git c/comments_.patch i/comments_.patch | |
new file mode 100644 | |
index 0000000..e69de29 | |
diff --git c/config/routes.rb i/config/routes.rb | |
index 262e55e..1daaf42 100644 | |
--- c/config/routes.rb | |
+++ i/config/routes.rb | |
@@ -6,6 +6,7 @@ Rails.application.routes.draw do | |
member do | |
post :join | |
end | |
+ resources :comments | |
end | |
namespace :saml do | |
diff --git c/db/migrate/20150225142330_add_comments.rb i/db/migrate/20150225142330_add_comments.rb | |
new file mode 100644 | |
index 0000000..2320c52 | |
--- /dev/null | |
+++ i/db/migrate/20150225142330_add_comments.rb | |
@@ -0,0 +1,12 @@ | |
+class AddComments < ActiveRecord::Migration | |
+ def change | |
+ create_table :comments do |t| | |
+ t.string :content | |
+ t.integer :hide_it | |
+ t.string :fun_level | |
+ t.string :mood | |
+ t.belongs_to :activity | |
+ t.timestamp | |
+ end | |
+ end | |
+end | |
diff --git c/db/schema.rb i/db/schema.rb | |
index bf59905..3e5e8e1 100644 | |
--- c/db/schema.rb | |
+++ i/db/schema.rb | |
@@ -11,7 +11,7 @@ | |
# | |
# It's strongly recommended that you check this file into your version control system. | |
-ActiveRecord::Schema.define(version: 20150204110615) do | |
+ActiveRecord::Schema.define(version: 20150225142330) do | |
create_table "activities", force: :cascade do |t| | |
t.string "name" | |
@@ -24,6 +24,14 @@ ActiveRecord::Schema.define(version: 20150204110615) do | |
add_index "activities_users", ["user_id", "activity_id"], name: "index_activities_users_on_user_id_and_activity_id" | |
+ create_table "comments", force: :cascade do |t| | |
+ t.string "content" | |
+ t.integer "hide_it" | |
+ t.string "fun_level" | |
+ t.string "mood" | |
+ t.integer "activity_id" | |
+ end | |
+ | |
create_table "users", force: :cascade do |t| | |
t.string "first_name" | |
t.string "last_name" | |
diff --git c/spec/features/activity_creation_feature_spec.rb i/spec/features/activity_creation_feature_spec.rb | |
index d65c102..94a004e 100644 | |
--- c/spec/features/activity_creation_feature_spec.rb | |
+++ i/spec/features/activity_creation_feature_spec.rb | |
@@ -16,4 +16,10 @@ describe 'New Activites Page' do | |
expect(page).to have_content('TestActivity') | |
end | |
end | |
+ | |
+ it 'test' do | |
+ user = create(:user, first_name: 'Test User') | |
+ logged_as user | |
+ visit activities_url | |
+ end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment