Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# Ignore bundler config.
/.bundle

/config/initializers/app_vars.rb

# Ignore all logfiles and tempfiles.
/log/*
!/log/.keep
Expand Down
39 changes: 15 additions & 24 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,37 @@
source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use postgresql as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

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

gem 'bcrypt', '~> 3.1.7'
gem 'delayed_job_active_record'
gem "delayed_job_web"
gem 'bootstrap-sass'
gem 'bootstrap-kaminari-views'
gem 'cancancan'
gem 'whenever', :require => false
gem 'carrierwave'
gem "mini_magick"


# , :group => :development
# Use Unicorn as the app server
# gem 'unicorn'

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

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem "hirb"
gem "awesome_print"
gem "interactive_editor"
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem "letter_opener"
gem 'spring'
gem "faker"
gem "rails-erd"
end
64 changes: 64 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,32 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.8)
arel (6.0.0)
autoprefixer-rails (5.2.0)
execjs
json
awesome_print (1.6.1)
bcrypt (3.1.10)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-kaminari-views (0.0.5)
kaminari (>= 0.13)
rails (>= 3.1)
bootstrap-sass (3.3.4.1)
autoprefixer-rails (>= 5.0.0.1)
sass (>= 3.2.19)
builder (3.2.2)
byebug (5.0.0)
columnize (= 0.9.0)
cancancan (1.10.1)
carrierwave (0.10.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
json (>= 1.7)
mime-types (>= 1.16)
choice (0.2.0)
chronic (0.10.2)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
Expand All @@ -52,8 +71,19 @@ GEM
coffee-script-source (1.9.1.1)
columnize (0.9.0)
debug_inspector (0.0.2)
delayed_job (4.0.6)
activesupport (>= 3.0, < 5.0)
delayed_job_active_record (4.0.3)
activerecord (>= 3.0, < 5.0)
delayed_job (>= 3.0, < 4.1)
delayed_job_web (1.2.10)
activerecord (> 3.0.0)
delayed_job (> 2.0.3)
sinatra (>= 1.4.4)
erubis (2.7.0)
execjs (2.5.2)
faker (1.4.3)
i18n (~> 0.5)
ffi (1.9.8)
globalid (0.3.5)
activesupport (>= 4.1.0)
Expand All @@ -69,18 +99,28 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
kaminari (0.16.3)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
launchy (2.4.3)
addressable (~> 2.3)
letter_opener (1.4.1)
launchy (~> 2.2)
loofah (2.0.2)
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.6.1)
mini_magick (4.2.7)
mini_portile (0.6.2)
minitest (5.7.0)
multi_json (1.11.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
pg (0.18.2)
rack (1.6.1)
rack-protection (1.5.3)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.1)
Expand All @@ -100,6 +140,11 @@ GEM
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-erd (1.4.0)
activerecord (>= 3.2)
activesupport (>= 3.2)
choice (~> 0.2.0)
ruby-graphviz (~> 1.2)
rails-html-sanitizer (1.0.2)
loofah (~> 2.0)
railties (4.2.1)
Expand All @@ -109,6 +154,7 @@ GEM
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rdoc (4.2.0)
ruby-graphviz (1.2.2)
sass (3.4.14)
sass-rails (5.0.3)
railties (>= 4.0.0, < 5.0)
Expand All @@ -119,6 +165,10 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
sinatra (1.4.6)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
spoon (0.0.4)
ffi
spring (1.3.6)
Expand All @@ -143,26 +193,40 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
whenever (0.9.4)
chronic (>= 0.6.3)

PLATFORMS
ruby

DEPENDENCIES
awesome_print
bcrypt (~> 3.1.7)
bootstrap-kaminari-views
bootstrap-sass
byebug
cancancan
carrierwave
coffee-rails (~> 4.1.0)
delayed_job_active_record
delayed_job_web
faker
hirb
interactive_editor
jbuilder (~> 2.0)
jquery-rails
letter_opener
mini_magick
pg
rails (= 4.2.1)
rails-erd
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
spring
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)
whenever

BUNDLED WITH
1.10.2
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree .
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/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/
2 changes: 2 additions & 0 deletions app/assets/stylesheets/bootstrap_and_overrides.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@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/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/
17 changes: 17 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,21 @@ 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?
current_user.present?
end

helper_method :user_signed_in?

def current_user
@current_user ||= User.find_by_id(session[:user_id])
end

helper_method :current_user

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

before_action :authenticate_user!

def create
comment_params = params.require(:comment).permit(:body)
@post = Post.find(params[:post_id])
@comment = Comment.new comment_params
@comment.post_id = params[:post_id]
@comment.user = current_user
respond_to do |format|
if @comment.save
# PostsMailer.notify_post_owner(@comment).deliver_now
PostsMailer.delay.notify_post_owner(@comment)
format.js { render }
format.html { redirect_to post_path(@post) }
else
@comments = Comment.search(@post.id)
format.js { render :create_failure }
format.html { render "/posts/show" }
end
end
end

def edit
@comment = Comment.find params[:id]
@post = Post.find params[:post_id]
end

def update
@post = Post.find params[:post_id]
comment_params = params.require(:comment).permit(:body)
@comment = Comment.find params[:id]
respond_to do |format|
if @comment.update comment_params
format.js { render :update }
format.html {redirect_to post_path(@post)}
else
format.js { render }
format.html {render :edit, notice: "Failed to update."}
end
end
end

def destroy
post = Post.find params[:post_id]
@comment = Comment.find params[:id]
@comment.destroy
respond_to do |format|
format.js { render }
format.html {
flash[:notice] = "Comment successfully deleted \n\n"
redirect_to post
}
end
end

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


before_action :authenticate_user!

def create
post = Post.find params[:post_id]
favourite = post.favourites.new
favourite.user = current_user
if favourite.save
redirect_to post, notice: "Post favourited"
else
redirect_to post, alert: "Error!"
end
end

def destroy
post = Post.find params[:post_id]
favourite = current_user.favourites.find_by_post_id(post)
favourite.destroy
redirect_to post, notice: "Un-favourited"
end

def index
@favourites = current_user.favourites
end

end
Loading