Created
February 25, 2015 14:52
-
-
Save kalabiyau/fcb60e0a21576c77a881 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 a431d0f..6537d2f 100644 | |
| --- c/app/views/activities/index.html.slim | |
| +++ i/app/views/activities/index.html.slim | |
| @@ -8,6 +8,15 @@ | |
| = a.name | |
| span.actions | |
| = link_to 'destroy', activity_path(a), method: :delete | |
| + - 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 a0d292e..9b3b318 100644 | |
| --- c/config/routes.rb | |
| +++ i/config/routes.rb | |
| @@ -2,7 +2,9 @@ Rails.application.routes.draw do | |
| root 'application#index' | |
| - resources :activities | |
| + resources :activities do | |
| + resources :comments | |
| + end | |
| namespace :saml do | |
| get :init | |
| 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