diff --git a/Gemfile b/Gemfile index 839131d..9a277d5 100644 --- a/Gemfile +++ b/Gemfile @@ -24,8 +24,7 @@ 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 'kaminari' @@ -38,6 +37,16 @@ gem 'hirb' gem 'faker' gem 'cancancan' + +gem 'simple_form' + +gem 'carrierwave' +gem 'mini_magick' + +gem 'delayed_job_active_record' +gem 'delayed_job_web' + +gem 'animate-rails' # Use Unicorn as the app server # gem 'unicorn' @@ -46,8 +55,10 @@ gem 'cancancan' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'pry' + gem 'pry-rails' gem 'byebug' - + gem "letter_opener" # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' diff --git a/Gemfile.lock b/Gemfile.lock index 70060c3..d822356 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,6 +36,9 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + addressable (2.3.8) + animate-rails (1.0.8) + rails arel (6.0.0) autoprefixer-rails (5.2.1) execjs @@ -51,6 +54,12 @@ GEM 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) + coderay (1.1.0) coffee-rails (4.1.0) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -60,6 +69,15 @@ 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) @@ -82,18 +100,32 @@ GEM 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) + method_source (0.8.2) 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) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-rails (0.3.4) + pry (>= 0.9.10) rack (1.6.1) + rack-protection (1.5.3) + rack rack-test (0.6.3) rack (>= 1.0) rails (4.2.1) @@ -132,6 +164,14 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + simple_form (3.1.0) + actionpack (~> 4.0) + activemodel (~> 4.0) + sinatra (1.4.6) + rack (~> 1.4) + rack-protection (~> 1.4) + tilt (>= 1.3, < 3) + slop (3.6.0) spoon (0.0.4) ffi spring (1.3.6) @@ -161,22 +201,31 @@ PLATFORMS ruby DEPENDENCIES + animate-rails awesome_print bcrypt (~> 3.1.7) bootstrap-sass (~> 3.3.5) byebug cancancan + carrierwave coffee-rails (~> 4.1.0) + delayed_job_active_record + delayed_job_web faker hirb interactive_editor jbuilder (~> 2.0) jquery-rails kaminari + letter_opener + mini_magick pg + pry + pry-rails rails (= 4.2.1) sass-rails (~> 5.0) sdoc (~> 0.4.0) + simple_form spring turbolinks uglifier (>= 1.3.0) diff --git a/README.md b/README.md new file mode 100644 index 0000000..37676a1 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +#Blog Features: + +##Homepage + +#### Site Navigation Bar: + - Visible on each page + - Drop-down for Post Categories + - User Log In / Sign Up / Log Out + - Click on site header leads to homepage + +#### Image carousel + - Useful for highlight news/updates/features + +#### Recent blog posts featured + - Link in title and full body shown + +##Creating Post + - Posts can have categories and tags in addition to the body and title + - Can add user collaborators for the post for management ability + +##Viewing Post + - Includes Liking, Favouriting, UpVoting + - Users can click 'Join' / 'Leave' + - File Attachment previews + - Comment box for other viewers + - Comments print avatar, body, and deletion link if applicable + +##Feautures Being Added in the Future: + - Working AJAX on the posts show page + - Nested drop down for All Posts > Post Index / Post Category in the future + - Implement clicking on image to link to parts of site + - Add image preview to Recent Posts featured diff --git a/README.rdoc b/README.rdoc deleted file mode 100644 index dd4e97e..0000000 --- a/README.rdoc +++ /dev/null @@ -1,28 +0,0 @@ -== README - -This README would normally document whatever steps are necessary to get the -application up and running. - -Things you may want to cover: - -* Ruby version - -* System dependencies - -* Configuration - -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... - - -Please feel free to use a different markup language if you do not plan to run -rake doc:app. diff --git a/app/assets/images/blue.jpg b/app/assets/images/blue.jpg new file mode 100644 index 0000000..5cc7ea4 Binary files /dev/null and b/app/assets/images/blue.jpg differ diff --git a/app/assets/images/retina_wood.png b/app/assets/images/retina_wood.png deleted file mode 100644 index 22f2450..0000000 Binary files a/app/assets/images/retina_wood.png and /dev/null differ diff --git a/app/assets/images/tree.png b/app/assets/images/tree.png new file mode 100644 index 0000000..4e627ec Binary files /dev/null and b/app/assets/images/tree.png differ diff --git a/app/assets/images/upfeathers.png b/app/assets/images/upfeathers.png deleted file mode 100644 index 8046ef3..0000000 Binary files a/app/assets/images/upfeathers.png and /dev/null differ diff --git a/app/assets/javascripts/favourites.coffee b/app/assets/javascripts/favourites.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/favourites.coffee @@ -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/ diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 2fde0c9..6ac0b84 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -6,6 +6,7 @@ h5 { color: #0079a3; font-size: 35pt; + letter-spacing: 15px; margin-top: 25px; margin-bottom:5px; padding-top: 0px; @@ -13,6 +14,9 @@ font-weight: lighter; } } +.header-text a:hover{ + text-decoration: none; +} .header-link { text-align: center; @@ -24,10 +28,11 @@ .user{ text-align: right; background: rgba(0, 121, 163, 0.6); + background-image: url("blue.jpg"); width:100%; margin-left: 0; margin-right: 0; - height: 28px; + height: 55px; padding-right: 5px; padding-top: 5px; padding-bottom: 5px; @@ -35,13 +40,25 @@ } .avatar { border-radius: 50%; + width: 45px; + height: 45px; +} +h1, h2, h3, h4 { + font-weight: lighter; } - .body { - padding-left: 10px; - padding-right: 10px; + padding-left: 10px; + padding-right: 10px; + .post-options { + display: inline-block; + } .button-options { height: auto; + padding: 25px; + .button-select { + display: inline-block; + float: left; + } .button-options button { } .button-long { @@ -90,7 +107,7 @@ background-color: #ff4c4c; } .fave { - background-color: #65e0fc; + background-color: #ffff7f; } } } @@ -107,3 +124,85 @@ padding-bottom: 15px; border-bottom: 1px dotted #0079a3; } +.post-image { + display: block; + padding-top: 20px; + padding-bottom: 20px; +} +/*Simple Form Styling*/ +.form-group label { + display: block; + font-size: 16pt; + font-family: Arial; + font-weight: lighter; + color: #074c62; + text-align: left; + margin-right: 10px; +} + +.form-group input { + padding: 5px; + margin-bottom: 10px; + background-color: #ececec; + border: 1px solid #0079a3; + border-radius: 10px; + width: 650px; + height: 40px; +} + +.form-group textarea { + padding: 5px; + margin-bottom: 10px; + background-color: #ececec; + border: 1px solid #0079a3; + border-radius: 10px; + width: 650px; + height: 120px; +} + +#post_category_id { + width: 325px; + height: 40px; + border-radius: 10px; + background-color: #0079a3; + color: #FFFFFF; + font-weight: lighter; + text-transform: uppercase; +} +.form-control { + font-size: 14pt; + font-weight: lighter; + color: #999999; + background-color: #0079a3; + border-radius: 10px; +} +.check-boxes label { + background-color: #0079a3; + height: 40px; + padding: 5px; + border-radius: 10px; + margin-right: 8px; + color: #FFFFFF; + font-weight: lighter; + text-transform: uppercase; + .collection_check_boxes { + margin-left: 10px; + margin-right: 15px; + height: 30px; + } +} +.submit-button { + width: auto; + height: 40px; + margin-top: 15px; + margin-left: 5px; + padding-top: 0px; + padding-left: 5px; + padding-bottom: 5px; + border-radius: 5px; + color: #333333; + font-size: 18pt; + font-weight: lighter; + text-align: center; + background-color: #ff7256; +} diff --git a/app/assets/stylesheets/favourites.scss b/app/assets/stylesheets/favourites.scss new file mode 100644 index 0000000..66cc292 --- /dev/null +++ b/app/assets/stylesheets/favourites.scss @@ -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/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b7b85c3..f9abe9d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,5 @@ 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 before_action :find_category @@ -21,5 +20,5 @@ def current_user def find_category @categories = Category.all end - + end diff --git a/app/controllers/collaborations_controller.rb b/app/controllers/collaborations_controller.rb index 51faa52..544928c 100644 --- a/app/controllers/collaborations_controller.rb +++ b/app/controllers/collaborations_controller.rb @@ -1,22 +1,23 @@ class CollaborationsController < ApplicationController - before_action :authenticate_user! - before_action :find_post + before_action :authenticate_user! + before_action :find_post - def create - @collaboration = Collaboration.new - @collaboration.user = current_user - @collaboration.post = @post - if @collaboration.save - redirect_to post_path(@post), notice: "Joined" - else - redirect_to post_path(@post), alert: "Can't Join" - end + def create + @collaboration = Collaboration.new + @collaboration.user = current_user + @collaboration.post = @post + if @collaboration.save + redirect_to post_path(@post), notice: "Joined" + else + redirect_to post_path(@post), alert: "Can't Join" end + end - private - def find_post - @post = Post.find params[:post_id] - end + private + + def find_post + @post = Post.find params[:post_id] + end end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index f2de207..e7a083b 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -8,19 +8,26 @@ def create @comment = Comment.new(comment_params) @comment.post = @post @comment.user = current_user - - if @comment.save - redirect_to post_path(@post), notice: "Comment created!" - else - render "/posts/show" + respond_to do |format| + if @comment.save + CommentsMailer.delay.notify_post_owner(@comment) + format.html { redirect_to post_path(@post), notice: "Comment created!" } + format.js + else + format.html { render "/posts/show" } + format.js { render :create_failure } + end end end def destroy - post = Post.find params[:post_id] - comment = Comment.find params[:id] - comment.destroy - redirect_to post_path(post), notice: "Comment deleted." + @post = Post.find params[:post_id] + @comment = Comment.find params[:id] + @comment.destroy + respond_to do |format| + format.html { redirect_to post_path(@post), notice: "Comment deleted." } + format.js { render :destroy } + end end end diff --git a/app/controllers/favourites_controller.rb b/app/controllers/favourites_controller.rb new file mode 100644 index 0000000..3434943 --- /dev/null +++ b/app/controllers/favourites_controller.rb @@ -0,0 +1,23 @@ +class FavouritesController < ApplicationController + + before_action :authenticate_user! + + def create + post = Post.find params[:post_id] + favourite = current_user.favourites.new + favourite.post = post + if favourite.save + redirect_to post, notice: "Question favourited" + else + redirect_to post, alert: "Can't favourite" + end + end + + def destroy + post = Post.find params[:post_id] + favourite = current_user.favourites.find params[:id] + favourite.destroy + redirect_to post, notice: "Un-Favourited" + end + +end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 414eaf3..a2a09e1 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,9 +1,8 @@ class PostsController < ApplicationController before_action :find_post, only: [:edit, :update, :destroy, :show] - before_action :authenticate_user!, except: [:index, :show] - before_action :authorize, only: [:edit, :update, :destroy] + before_action :authorize, only: [:edit] def index @posts = Post.page(params[:page]).per(8).order("id ASC") @@ -14,7 +13,6 @@ def new end def create - post_params = params.require(:post).permit([:title, :body, :category_id, {tag_ids: []}]) @post = Post.new(post_params) @post.user = current_user @@ -29,6 +27,7 @@ def show @comment = Comment.new @like = @post.like_for(current_user) @vote = @post.vote_for(current_user) + @favourite = @post.favourite_for(current_user) @collaboration = @post.collaborating_users end @@ -36,7 +35,6 @@ def edit end def update - post_params = params.require(:post).permit([:title, :body, :category_id, {tag_ids: []}]) if @post.update(post_params) redirect_to post_path(@post), notice: "Post has been updated" else @@ -45,18 +43,26 @@ def update end def destroy + authorize_delete @post.destroy redirect_to posts_path, notice: "Post Deleted" end private + def post_params + post_params = params.require(:post).permit([:title, :body, :category_id, {tag_ids: []}, :image]) + end + def find_post @post = Post.find params[:id] end def authorize - redirect_to root_path, alert: "Access denied." unless can? :manage, @post + redirect_to root_path, alert: "Access denied." unless can? :edit, @post end + def authorize_delete + redirect_to post_path(@post), alert: "Access denied" unless can? :destroy, @post + end end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb deleted file mode 100644 index 0ea233d..0000000 --- a/app/controllers/tags_controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class TagsController < ApplicationController -end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a325c5a..c1c469e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,42 +1,46 @@ class UsersController < ApplicationController - before_action :user_params, only: [:create, :edit] - - def new - @user = User.new - end - - def create - @user = User.new user_params - if @user.save - session[:user_id] = @user.id - redirect_to root_path - else - render :new - end - end - -def edit - @user = current_user -end + before_action :authenticate_user!, only: [:edit, :update] + before_action :user_params, only: [:create, :update] -def update - @user = current_user - if !@user.authenticate(params[:user][:current_password]) - flash[:alert] = "You've entered the wrong password" - render :edit - elsif @user.update(user_params) - redirect_to edit_users_path, notice: "Information updated" - else - render :edit + def new + @user = User.new + end + + def create + @user = User.new user_params + if @user.save + session[:user_id] = @user.id + redirect_to root_path, notice: "Logged In!" + else + render :new + end + end + + def edit + @user = current_user + end + + def update + @user = current_user + if !@user.authenticate(params[:user][:current_password]) + flash[:alert] = "You've entered the wrong password" + render :edit + elsif @user.update(user_params) + redirect_to user_path(@user), notice: "Information updated" + else + render :edit + end + end + + def show + @user = User.find params[:id] end -end - -private -def user_params - params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation) -end + private + def user_params + params.require(:user).permit(:first_name, :last_name, :email, :avatar, :password, :password_confirmation) + end end diff --git a/app/controllers/votes_controller.rb b/app/controllers/votes_controller.rb index aaf6665..b2d4840 100644 --- a/app/controllers/votes_controller.rb +++ b/app/controllers/votes_controller.rb @@ -1,35 +1,42 @@ class VotesController < ApplicationController - before_action :authenticate_user! def create - post = Post.find params[:post_id] - - vote = current_user.votes.new(vote_params) - vote.post = post - if vote.save - redirect_to post, notice: "Voted!" - else - redirect_to post, alert: "Couldn't vote" + @post = Post.find params[:post_id] + @vote = current_user.votes.new(vote_params) + @vote.post = @post + respond_to do |format| + if @vote.save + format.html { redirect_to @post, notice: "Voted!" } + format.js { render } + else + format.html { redirect_to @post, alert: "Couldnt Vote!" } + format.js { render } + end end end - def destroy - post = Post.find params[:post_id] - - vote = current_user.votes.find params[:id] - vote.destroy - redirect_to post, notice: "Vote Removed" - end - def update - post = Post.find params[:post_id] + @post = Post.find params[:post_id] + @vote = current_user.votes.find params[:id] + respond_to do |format| + if @vote.update(vote_params) + format.html { redirect_to @post, notice: "Vote updated!" } + format.js { render } + else + format.html { redirect_to @post, alert: "Vote couldn't update" } + format.js { render } + end + end + end - vote = current_user.votes.find params[:id] - if vote.update(vote_params) - redirect_to post, notice: "Vote Changed!" - else - redirect_to post, alert: "Vote Un-Changed" + def destroy + @post = Post.find params[:post_id] + @vote = current_user.votes.find params[:id] + @vote.destroy + respond_to do |format| + format.html { redirect_to @post, notice: "Vote removed" } + format.js { render } end end diff --git a/app/helpers/favourites_helper.rb b/app/helpers/favourites_helper.rb new file mode 100644 index 0000000..907962e --- /dev/null +++ b/app/helpers/favourites_helper.rb @@ -0,0 +1,2 @@ +module FavouritesHelper +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..d25d889 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: "from@example.com" + layout 'mailer' +end diff --git a/app/mailers/comments_mailer.rb b/app/mailers/comments_mailer.rb new file mode 100644 index 0000000..755b51e --- /dev/null +++ b/app/mailers/comments_mailer.rb @@ -0,0 +1,8 @@ +class CommentsMailer < ApplicationMailer + + def notify_post_owner(comment) + @comment = comment + @post = comment.post + mail(to: @post.user.email, subject: "A post has been commented on!") + end +end diff --git a/app/models/ability.rb b/app/models/ability.rb index ff4087a..1e94485 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -13,7 +13,7 @@ def initialize(user) end can :manage, Comment do |comment| - comment.user == user + comment.user == user || comment.post.user == user end end end diff --git a/app/models/favourite.rb b/app/models/favourite.rb new file mode 100644 index 0000000..40ae00c --- /dev/null +++ b/app/models/favourite.rb @@ -0,0 +1,6 @@ +class Favourite < ActiveRecord::Base + belongs_to :user + belongs_to :post + + validates :post_id, uniqueness: {scope: :user_id} +end diff --git a/app/models/post.rb b/app/models/post.rb index d36d610..922fb11 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1,5 +1,7 @@ class Post < ActiveRecord::Base + mount_uploader :image, ImageUploader + belongs_to :category belongs_to :user @@ -12,6 +14,9 @@ class Post < ActiveRecord::Base has_many :taggings, dependent: :destroy has_many :tags, through: :taggings + has_many :favourites, dependent: :destroy + has_many :favouriting_users, through: :favourites, source: :user + has_many :collaborations, dependent: :destroy has_many :collaborating_users, through: :collaborations, source: :user @@ -21,6 +26,7 @@ class Post < ActiveRecord::Base scope :recent_three, lambda { order("updated_at DESC").limit(3) } + def liked_by?(user) likes.where(user: user).present? end @@ -29,6 +35,14 @@ def like_for(user) likes.find_by_user_id(user) end + def favourited_by?(user) + favourites.where(user: user).present? + end + + def favourite_for(user) + favourites.find_by_user_id(user) + end + def vote_for(user) votes.find_by_user_id(user) end diff --git a/app/models/user.rb b/app/models/user.rb index d92217f..ebbf895 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,7 @@ class User < ActiveRecord::Base + mount_uploader :avatar, ImageUploader + has_secure_password has_many :posts, dependent: :destroy @@ -9,7 +11,13 @@ class User < ActiveRecord::Base has_many :votes, dependent: :destroy has_many :voted_posts, through: :votes, source: :post has_many :collaborations, dependent: :destroy - has_many :collaborated_posts, through: :collaborations, source: :posts + has_many :collaborated_posts, through: :collaborations, source: :post + + has_many :taggings, dependent: :destroy + has_many :tagged_posts, through: :taggings, source: :post + + has_many :favourites, dependent: :destroy + has_many :favourited_posts, through: :favourites, source: :post validates :first_name, presence: true validates :last_name, presence: true @@ -20,4 +28,12 @@ def full_name "#{first_name} #{last_name}".strip.squeeze(" ") end + def recent_five_made + posts.order("updated_at DESC").limit(5) + end + + def recent_five_joins + collaborated_posts.order("created_at DESC").limit(5) + end + end diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb new file mode 100644 index 0000000..1898658 --- /dev/null +++ b/app/uploaders/image_uploader.rb @@ -0,0 +1,26 @@ +# encoding: utf-8 + +class ImageUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + version :square_thumb do + process :resize_to_fill => [45,45] + end + + version :resized_image do + process :resize_to_fill => [300,300] + end +end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb new file mode 100644 index 0000000..17c2e2d --- /dev/null +++ b/app/views/comments/_comment.html.erb @@ -0,0 +1,29 @@ +<% @post.comments.each do |comment| %> +
+
+
+ <% if comment.user.avatar.present? %> + <%= image_tag comment.user.avatar.url(:square_thumb), :class => "img-circle" %> + <% else %> + <%= image_tag ("tree.png"), :class => "avatar" %> + <% end %> +
+ <%= comment.user.full_name %> +
+
+
+

<%= comment.body %>

+ Posted on: <%= formatted_date(comment.created_at) %> +
+ + <% if can?(:delete, comment) %> +
+ <%= link_to ">> Delete Comment", post_comment_path(@post, comment), method: :delete, data: {confirm: "Are you sure?"} %> +
+ <% end %> +
+
+
+
+
+<% end %> diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb new file mode 100644 index 0000000..f663b0d --- /dev/null +++ b/app/views/comments/_form.html.erb @@ -0,0 +1,13 @@ +<% if @comment.errors.any? %> + + <% end %> + +<%= simple_form_for [@post, @comment], :remote => true do |f| %> + <%= f.text_area :body, :size => "50x8" %> +
+ <%= f.submit 'Comment!', :class => "submit-button" %> +<% end %> diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb new file mode 100644 index 0000000..6330834 --- /dev/null +++ b/app/views/comments/create.js.erb @@ -0,0 +1,4 @@ +$("#comments").prepend("<%= j render 'comment', comment: @comment %>"); + +<% @comment = Comment.new %> +$("#new_comment").replaceWith("<%= j render 'form' %>"); diff --git a/app/views/comments/create_failure.js.erb b/app/views/comments/create_failure.js.erb new file mode 100644 index 0000000..a00b123 --- /dev/null +++ b/app/views/comments/create_failure.js.erb @@ -0,0 +1 @@ +$("#new_comment").replaceWith("<%= j render 'form' %>"); diff --git a/app/views/comments/destroy.js.erb b/app/views/comments/destroy.js.erb new file mode 100644 index 0000000..c859aca --- /dev/null +++ b/app/views/comments/destroy.js.erb @@ -0,0 +1 @@ +$("#<% dom_id(@comment) %>").fadeOut(); diff --git a/app/views/comments_mailer/notify_post_owner.html.erb b/app/views/comments_mailer/notify_post_owner.html.erb new file mode 100644 index 0000000..b3b243d --- /dev/null +++ b/app/views/comments_mailer/notify_post_owner.html.erb @@ -0,0 +1,10 @@ + + +

Hey there, <%= @post.user.full_name %>,

+

Your post, titled: <%= @post.title %>

+

Has been commented on. It reads:

+

<%= @comment.body %>

+ +

Have a great one and see you on the blog soon!

+ + diff --git a/app/views/homes/about.html.erb b/app/views/homes/about.html.erb index b6fa616..0f65265 100644 --- a/app/views/homes/about.html.erb +++ b/app/views/homes/about.html.erb @@ -1,4 +1,6 @@ -

Hi, I'm Tien.

-

This is my about page

+
+

Hi, I'm Tien.

+

This is my about page

-<%= image_tag "http://i.imgur.com/9f4lbXW.jpg" %> + <%= image_tag "http://i.imgur.com/9f4lbXW.jpg" %> +
diff --git a/app/views/homes/home.html.erb b/app/views/homes/home.html.erb index a6e8135..fdfe694 100644 --- a/app/views/homes/home.html.erb +++ b/app/views/homes/home.html.erb @@ -1,4 +1,4 @@ -