Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
cb479ec
Added home controller
Apr 7, 2016
89a0d9d
Added about page
Apr 7, 2016
6995e99
added some untracked files back in
Apr 7, 2016
de96dbb
Added menu links
Apr 7, 2016
a5fbabb
Added default route
Apr 7, 2016
8d81025
Added default route
Apr 7, 2016
6ca1725
Made sure files in ./public and some personal notes stayed out of git.
Apr 11, 2016
86269ca
Added A model for Blog posts (Post), blog post comments (Comment), a …
Apr 11, 2016
7b49308
Added validation for Post. Post now requres the title to be required …
Apr 11, 2016
8184234
Attach comments to posts
Apr 12, 2016
08b15cc
added controller for blog posts
Apr 12, 2016
63a82bc
Added routes for blog posts
Apr 12, 2016
6eb0da9
Added faker gem and used to create a seed for blog posts
Apr 12, 2016
a7f7bc9
Added blog post index with view and controller method
Apr 12, 2016
9e21189
renamed blog posts controller to just posts
Apr 13, 2016
2e627ae
added in slim templating gem
Apr 13, 2016
49c591b
added in form for creating or editing blog posts and the relevent views
Apr 13, 2016
7e93059
added a show view for an indevidual blog post
Apr 13, 2016
eeaaf37
changed helper functions (find_post, post_params) to private
Apr 13, 2016
226401c
added delete blog post functionality, with UI in posts show view
Apr 13, 2016
4580006
added edit UI to blog post#show
Apr 13, 2016
fd51ac2
Minor UI changes
Apr 13, 2016
84a0430
added Blog Posts index link to menu bar
Apr 13, 2016
49a7f5a
added coments controller
Apr 13, 2016
8f08b31
added comments route
Apr 13, 2016
8d623ee
Filled in comments controller (full sweep)
Apr 13, 2016
01efa87
Added comment edit and new forms
Apr 13, 2016
8bb1bb1
fix over lax input field permit
Apr 13, 2016
60e2adc
added edid, index and show views for comments. index probably won't b…
Apr 13, 2016
76083ba
fixed new blog post and new comments. mostly in the respective contro…
Apr 14, 2016
3b4f610
fixed new blog post controller action and added flash messages in
Apr 14, 2016
fa39548
Merged in comments branch
Apr 14, 2016
306fe4c
.gitignore ed bybug history
Apr 14, 2016
4da1076
set up blog project for rspec testing, including posts controllers te…
Apr 14, 2016
186f827
Added blog post model rspec test
Apr 15, 2016
9546afc
refectored rspec test for post
Apr 16, 2016
5715260
added a comment
Apr 16, 2016
632ac8d
comments now display under blog posts and can be created there
Apr 16, 2016
9fc29d8
waiting til later to introduce users
Apr 17, 2016
abd7d87
added body validation
Apr 17, 2016
ef54842
added category model tests
Apr 17, 2016
e6926a6
Added in categories for posts
Apr 17, 2016
4f03df1
moved notice || alert display to layout instead of restricted to indi…
Apr 17, 2016
38a4cfb
fixed wrong path to partial
Apr 17, 2016
8d89f00
added in category support, for blog posts, in views and controller
Apr 17, 2016
2e45b85
Merge branch 'categories'
Apr 17, 2016
6c063db
added user model
Apr 19, 2016
cc7cc2b
add user references to posts and comments models
Apr 19, 2016
a6ef349
add user validations and fixed user model password check with has_sec…
Apr 19, 2016
6096642
fixed up user validations rspec test
Apr 19, 2016
67a7074
added user controller and filled in a create user and edit user forms…
Apr 19, 2016
5d2f918
added ability to add a user
Apr 19, 2016
30cab77
added in login page
Apr 19, 2016
46fb16a
fixes up login paged
Apr 20, 2016
fe04a77
added ability to log in and out. Had to implement destory method in t…
Apr 20, 2016
195727d
added user authentication for backend
Apr 20, 2016
eadae0e
don't show edit or delete buttons if not logged in
Apr 20, 2016
e830f12
redirect to post when comment is delete insetead of non exsistant ind…
Apr 20, 2016
6174a5f
start on adding per user permissons by restricting posts passed by co…
Apr 20, 2016
c05082a
Revert "start on adding per user permissons by restricting posts pass…
Apr 20, 2016
aefb538
Add cancancan and use to manage blog post permissions
Apr 23, 2016
fbd299d
Rename confusing method name. Is purly a refactor
Apr 23, 2016
6b956ba
fixes flash alert and wierd pasting typo
Apr 23, 2016
457ffe5
add cancancan authoriztion for comments
Apr 23, 2016
9f4ad16
unfinished users rspec tests
Apr 28, 2016
6f68c92
add a user factory
Apr 28, 2016
ff50791
add rspec test for users controller
Apr 28, 2016
c99be8e
add feature to allow a user favourite blog posts and to view all thei…
IDFSimpson May 15, 2016
4b9d4eb
fix comment permissions and make respond propery to an ivalid comment…
IDFSimpson May 15, 2016
ceb1a89
add bootsrap gem and enable
IDFSimpson May 15, 2016
f590f3b
add bootstrap styling to navbar and put the everything in a container.
IDFSimpson May 15, 2016
f492423
add styling to flash notices
IDFSimpson May 15, 2016
39cd958
assign the signed in user to be the creator of a post
IDFSimpson May 15, 2016
657b744
add display of user for each comment and fix comment styling
IDFSimpson May 15, 2016
4cbbc67
add icons to edit delete action for comments and posts. Will remove t…
IDFSimpson May 15, 2016
5e140d7
add new comment link to navbar and minor styling. I'll change to simp…
IDFSimpson May 15, 2016
d2e5eb2
fix bug where unfavoriting delete its host post becuase of db dependa…
IDFSimpson May 15, 2016
35abc36
change to using ajax to favourite and unfavourite and for the list of…
IDFSimpson May 18, 2016
390e49b
Merge branch 'add_ajax_to_favourites_and_controller' into integration
IDFSimpson May 18, 2016
66f15b7
ajaxify comment list and favourite/unfavourite
IDFSimpson May 18, 2016
8dd1bd6
Merge branch 'add_ajax_to_favourites_and_controller' into integration
IDFSimpson May 18, 2016
a09af43
fix bug. Don't need to have a post in the user's favourites index.
IDFSimpson May 19, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
/log/*
!/log/.keep
/tmp
models_setup.txt
models_setup.txt~
public/img/
.byebug_history
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
12 changes: 10 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,26 @@ gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

gem 'slim'

gem 'cancancan'

gem 'bootstrap-sass'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'rspec-rails'
gem 'faker'
gem 'factory_girl_rails'
end

group :development do
Expand All @@ -44,4 +53,3 @@ group :development do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end

45 changes: 44 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
autoprefixer-rails (6.3.6)
execjs
bcrypt (3.1.11)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.3.6)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.2)
byebug (8.2.2)
cancancan (1.13.1)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.1.x)
Expand All @@ -50,8 +57,16 @@ GEM
coffee-script-source (1.10.0)
concurrent-ruby (1.0.1)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.6.0)
factory_girl (4.7.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.7.0)
factory_girl (~> 4.7.0)
railties (>= 3.0.0)
faker (1.6.3)
i18n (~> 0.5)
globalid (0.3.6)
activesupport (>= 4.1.0)
i18n (0.7.0)
Expand Down Expand Up @@ -106,6 +121,23 @@ GEM
rake (11.1.2)
rdoc (4.2.2)
json (~> 1.4)
rspec-core (3.4.4)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-mocks (3.4.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-rails (3.4.2)
actionpack (>= 3.0, < 4.3)
activesupport (>= 3.0, < 4.3)
railties (>= 3.0, < 4.3)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
sass (3.4.22)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
Expand All @@ -116,6 +148,9 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
slim (3.0.6)
temple (~> 0.7.3)
tilt (>= 1.3.3, < 2.1)
spring (1.6.4)
sprockets (3.6.0)
concurrent-ruby (~> 1.0)
Expand All @@ -124,6 +159,7 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
temple (0.7.6)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.2)
Expand All @@ -143,18 +179,25 @@ PLATFORMS
ruby

DEPENDENCIES
bcrypt (~> 3.1.7)
bootstrap-sass
byebug
cancancan
coffee-rails (~> 4.1.0)
factory_girl_rails
faker
jbuilder (~> 2.0)
jquery-rails
pg (~> 0.15)
rails (= 4.2.6)
rspec-rails
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
slim
spring
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)

BUNDLED WITH
1.11.2
1.12.2
3 changes: 3 additions & 0 deletions app/assets/javascripts/comments.coffee
Original file line number Diff line number Diff line change
@@ -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://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/favourites.coffee
Original file line number Diff line number Diff line change
@@ -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://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/home.coffee
Original file line number Diff line number Diff line change
@@ -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://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/posts.coffee
Original file line number Diff line number Diff line change
@@ -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://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/sessions.coffee
Original file line number Diff line number Diff line change
@@ -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://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/users.coffee
Original file line number Diff line number Diff line change
@@ -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://coffeescript.org/
4 changes: 4 additions & 0 deletions app/assets/stylesheets/bootstrap_and_overrides.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body { padding-top: 70px; }

@import "bootstrap-sprockets";
@import "bootstrap"
3 changes: 3 additions & 0 deletions app/assets/stylesheets/comments.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the comments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/favourites.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the favourites controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/home.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the home controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/posts.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the posts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/sessions.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/users.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
16 changes: 16 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,20 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

def authenticate_user!
redirect_to new_session_path, notice: "Please sign in!" unless user_signed_in?
end

def user_signed_in?
session[:user_id].present?
end
helper_method :user_signed_in?

# Cancancan's ability.rb will use this if it exsists, I think -- IDFS
def current_user
@current_user ||= User.find session[:user_id] if user_signed_in?
end
helper_method :current_user

end
70 changes: 70 additions & 0 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class CommentsController < ApplicationController

before_action :authenticate_user!
before_action(:find_comment, {only: [:show, :edit, :update, :destroy]})
before_action :authorize_comment, only: [:edit, :update, :destroy]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just write
before_action :find_comment, only: [:show, :edit, :update, :destroy]
to make them consistent.



def index
@comments = Comment.all
end

def new
@comment = Comment.new
end

def create
@post = Post.find params[:post_id]
@comment = Comment.new(comment_params)
@comment.post = @post
@comment.user = current_user
respond_to do |format|
if @comment.save
flash[:notice] = "Comment Created"
format.html { redirect_to post_path(@post) }
format.js { render :reload }
else
flash[:alert] = "Error! Comment not created"
format.html { render "/posts/show" }
format.js { render :reload }
end
end
end

def edit
end

# def update
# if @comment.update comment_params
# redirect_to comment_path(@comment), notice: "Comment updated!"
# else
# render :edit
# end
# end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to the commented out update action?

def show
end

def destroy
@post = Post.find params[:post_id]
@comment.destroy
redirect_to post_path(@post), notice: "Your comment was deleted."
end


private

def find_comment
@comment = Comment.find params[:id]
end

def authorize_comment
flash[:alert] = "You do not have permission to manage this comment"
redirect_to root_path unless can? :manage, @comment
end

def comment_params
params.require(:comment).permit(:body)
end

end
40 changes: 40 additions & 0 deletions app/controllers/favourites_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class FavouritesController < ApplicationController
before_action :authenticate_user!
before_action :find_post, only: [:create, :destroy]

def create
favourite = Favourite.new
favourite.post = @post
favourite.user = current_user
respond_to do |format|
if favourite.save
format.html { redirect_to post_path(@post), notice: "Thanks for favouriting!" }
format.js { render :modify_favourite }
else
format.html { redirect_to post_path(@post), alert: "Can't favourite! Have you already favourited?" }
format.js { render :modify_favourite }
end
end
end

def destroy
favourite = current_user.favourites.find params[:id]
favourite.destroy
respond_to do |format|
format.html { redirect_to post_path(@post), notice: "Favourite removed!" }
format.js { render :modify_favourite }
end
end

def index
@favourites = current_user.favourites.all
end

@yiivan yiivan May 25, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user do not have any favourite post, it will throw an exception. Please refer my notes on favourites/index.html.erb


private

def find_post
@post ||= Post.find params[:post_id]
end

end
11 changes: 11 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Home and static pages go in HomeController
class HomeController < ApplicationController
def home

end

def about

end

end
Loading