diff --git a/.gitignore b/.gitignore index 5b61ab0..6867b3b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ /log/* !/log/.keep /tmp +models_setup.txt +models_setup.txt~ +public/img/ +.byebug_history diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..83e16f8 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/Gemfile b/Gemfile index b38d1b2..16ee7fe 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,7 @@ 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' @@ -32,9 +32,18 @@ gem 'sdoc', '~> 0.4.0', group: :doc # 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 @@ -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 - diff --git a/Gemfile.lock b/Gemfile.lock index b0631ce..3c82d3a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/app/assets/javascripts/comments.coffee b/app/assets/javascripts/comments.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/comments.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/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/javascripts/home.coffee b/app/assets/javascripts/home.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/home.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/javascripts/posts.coffee b/app/assets/javascripts/posts.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/posts.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/javascripts/sessions.coffee b/app/assets/javascripts/sessions.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/sessions.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/javascripts/users.coffee b/app/assets/javascripts/users.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/users.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/bootstrap_and_overrides.scss b/app/assets/stylesheets/bootstrap_and_overrides.scss new file mode 100644 index 0000000..d3e0995 --- /dev/null +++ b/app/assets/stylesheets/bootstrap_and_overrides.scss @@ -0,0 +1,4 @@ +body { padding-top: 70px; } + +@import "bootstrap-sprockets"; +@import "bootstrap" diff --git a/app/assets/stylesheets/comments.scss b/app/assets/stylesheets/comments.scss new file mode 100644 index 0000000..3722c12 --- /dev/null +++ b/app/assets/stylesheets/comments.scss @@ -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/ 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/assets/stylesheets/home.scss b/app/assets/stylesheets/home.scss new file mode 100644 index 0000000..f0ddc68 --- /dev/null +++ b/app/assets/stylesheets/home.scss @@ -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/ diff --git a/app/assets/stylesheets/posts.scss b/app/assets/stylesheets/posts.scss new file mode 100644 index 0000000..1a7e153 --- /dev/null +++ b/app/assets/stylesheets/posts.scss @@ -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/ diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000..7bef9cf --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -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/ diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 0000000..1efc835 --- /dev/null +++ b/app/assets/stylesheets/users.scss @@ -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/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e..0b8eb52 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 0000000..72597fc --- /dev/null +++ b/app/controllers/comments_controller.rb @@ -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] + + + 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 + + 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 diff --git a/app/controllers/favourites_controller.rb b/app/controllers/favourites_controller.rb new file mode 100644 index 0000000..cefdad9 --- /dev/null +++ b/app/controllers/favourites_controller.rb @@ -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 + + + private + + def find_post + @post ||= Post.find params[:post_id] + end + +end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..06dbcc3 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,11 @@ +# Home and static pages go in HomeController +class HomeController < ApplicationController + def home + + end + + def about + + end + +end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb new file mode 100644 index 0000000..9f6c165 --- /dev/null +++ b/app/controllers/posts_controller.rb @@ -0,0 +1,64 @@ +class PostsController < ApplicationController + + before_action :authenticate_user!, except: [:index, :show] + before_action(:find_post, {only: [:show, :edit, :update, :destroy]}) + before_action :authorize_post, only: [:edit, :update, :destroy] + + + + def index + @posts = Post.all + end + + def new + @post = Post.new + end + + def create + @post = Post.new(post_params) + @post.user = current_user + + if @post.save + flash[:notice] = "Post Created" + redirect_to post_path(@post) + else + flash[:alert] = "Error! Post not created" + render :new + end + end + + def edit + end + + def update + if @post.update post_params + redirect_to post_path(@post), notice: "Blog Post updated!" + else + render :edit + end + end + + def show + @comment = Comment.new + end + + def destroy + @post.destroy + redirect_to posts_path, notice: "The blog post #{@post.title} was deleted." + end + + private + + def authorize_post + flash[:alert] ="You do not have permission to delete the blog post #{@post.title}" + redirect_to root_path unless can? :manage, @post + end + + def find_post + @post = Post.find params[:id] + end + + def post_params + params.require(:post).permit([:title, :body, :category_id]) + end +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000..93d3599 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,21 @@ +class SessionsController < ApplicationController + def new + end + + def create + user = User.find_by_email params[:email] + if user && user.authenticate(params[:password]) + session[:user_id] = user.id + redirect_to root_path, notice: "Signed In!" + else + flash[:alert] = "Wrong Credentials!" + render :new + end + end + + def destroy + session[:user_id] = nil + redirect_to root_path, notice: "Logged out" + end + +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..e8002ce --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,21 @@ +class UsersController < ApplicationController + + def new + @user = User.new + end + + def create + user_params = params.require(:user).permit(:first_name, :last_name, :email, + :password, :password_confirmation) + @user = User.new user_params + if @user.save + # we log the user in by setting the session :user_id to the user's id + # in our database so we can identify the user who is logged in by their id + session[:user_id] = @user.id + redirect_to root_path, notice: "Account created!" + else + render :new + end + end + +end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb new file mode 100644 index 0000000..0ec9ca5 --- /dev/null +++ b/app/helpers/comments_helper.rb @@ -0,0 +1,2 @@ +module CommentsHelper +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/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000..23de56a --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb new file mode 100644 index 0000000..7fefcf4 --- /dev/null +++ b/app/helpers/posts_helper.rb @@ -0,0 +1,5 @@ +module PostsHelper + def user_favourite + @user_favourite ||= @post.favourite_for(current_user) + end +end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 0000000..309f8b2 --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000..2310a24 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/models/ability.rb b/app/models/ability.rb new file mode 100644 index 0000000..8d60438 --- /dev/null +++ b/app/models/ability.rb @@ -0,0 +1,51 @@ +class Ability + include CanCan::Ability + + def initialize(user) + + user ||= User.new # guest user (not logged in) + + # TODO Add admin. Commented out until admin column is added to users table + # if user.admin? + # can :manage, :all + # else + # can :read, :all + # end + + can :manage, Post do |post| + post.user == user + end + + can :manage, Comment do |comment| + comment.user == user || comment.post.user == user + end + + + # Define abilities for the passed in user here. For example: + # + # user ||= User.new # guest user (not logged in) + # if user.admin? + # can :manage, :all + # else + # can :read, :all + # end + # + # The first argument to `can` is the action you are giving the user + # permission to do. + # If you pass :manage it will apply to every action. Other common actions + # here are :read, :create, :update and :destroy. + # + # The second argument is the resource the user can perform the action on. + # If you pass :all it will apply to every resource. Otherwise pass a Ruby + # class of the resource. + # + # The third argument is an optional hash of conditions to further filter the + # objects. + # For example, here the user can only update published articles. + # + # can :update, Article, :published => true + # + # See the wiki for details: + # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities + end +end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000..9dc026c --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,5 @@ +class Category < ActiveRecord::Base + has_many :posts, dependent: :nullify + + validates :title, presence: true, uniqueness: true +end diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..c5ab164 --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,7 @@ +class Comment < ActiveRecord::Base + belongs_to :customer + belongs_to :post + belongs_to :user + + validates :body, presence: :true +end diff --git a/app/models/contact.rb b/app/models/contact.rb new file mode 100644 index 0000000..26a68e5 --- /dev/null +++ b/app/models/contact.rb @@ -0,0 +1,3 @@ +class Contact < ActiveRecord::Base + +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 new file mode 100644 index 0000000..8cf2578 --- /dev/null +++ b/app/models/post.rb @@ -0,0 +1,29 @@ +class Post < ActiveRecord::Base + # title should be required & unique + validates :title, presence: true, uniqueness: true, length: {minimum: 7} + validates :body, presence: true + + has_many :comments, dependent: :nullify + belongs_to :category + belongs_to :user + + has_many :favourites, dependent: :nullify + has_many :favouriting_users, through: :favourites, source: :users + + def body_snippet + body.length > 99 ? "#{self.body[0...99]}..." : body + end + + def category_or_unknown + category ? category.title : "Unknown Category" + end + + def favourite_for(user) + favourites.find_by_user_id user if user + end + + def favourited_by?(user) + favourites.find_by_user_id(user.id).present? + end + +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..56bc805 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,17 @@ +class User < ActiveRecord::Base + has_many :posts + has_many :comments + + has_secure_password + + validates :first_name, presence: true + validates :last_name, presence: true + + VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i + validates :email, presence: true, uniqueness: true, format: VALID_EMAIL_REGEX + + validates :password, presence: true + + has_many :favourites, dependent: :nullify + has_many :favourite_posts, through: :favourites, source: :post +end diff --git a/app/views/comments/_comment.html.slim b/app/views/comments/_comment.html.slim new file mode 100644 index 0000000..3006469 --- /dev/null +++ b/app/views/comments/_comment.html.slim @@ -0,0 +1,14 @@ +div + span + = comment.body + | by + = comment.user.email + | + span + - if can? :delete, comment + = link_to "delete", post_comment_path(@post, comment), + data: {confirm: "Are you sure?"}, + method: :delete, + remote: true, + class: "glyphicon glyphicon-remove" + diff --git a/app/views/comments/_comment_form.html.slim b/app/views/comments/_comment_form.html.slim new file mode 100644 index 0000000..d0ca6d4 --- /dev/null +++ b/app/views/comments/_comment_form.html.slim @@ -0,0 +1,3 @@ += simple_form_for @comment do |f| + = f.input :body, + = f.submit diff --git a/app/views/comments/_form.html.slim b/app/views/comments/_form.html.slim new file mode 100644 index 0000000..971c33a --- /dev/null +++ b/app/views/comments/_form.html.slim @@ -0,0 +1,5 @@ += comment.errors.full_messages.join(", ") += form_for comment, url: post_comments_path(@post) do |f| + = form_for [@post, comment], remote: true do |form_helper| + = form_helper.text_area :body, class: "form-control" + = form_helper.submit diff --git a/app/views/comments/edit.html.slim b/app/views/comments/edit.html.slim new file mode 100644 index 0000000..79977c3 --- /dev/null +++ b/app/views/comments/edit.html.slim @@ -0,0 +1,3 @@ +h2 Edit Comment + += render "comment_form" diff --git a/app/views/comments/index.html.slim b/app/views/comments/index.html.slim new file mode 100644 index 0000000..af48bec --- /dev/null +++ b/app/views/comments/index.html.slim @@ -0,0 +1,5 @@ +h2 All Comments List + +- @comments.each do |c| + div + = c.body diff --git a/app/views/comments/new.html.slim b/app/views/comments/new.html.slim new file mode 100644 index 0000000..9557503 --- /dev/null +++ b/app/views/comments/new.html.slim @@ -0,0 +1,3 @@ +h2 New Comment + += render "comments/comment_form" diff --git a/app/views/comments/reload.js.erb b/app/views/comments/reload.js.erb new file mode 100644 index 0000000..5347512 --- /dev/null +++ b/app/views/comments/reload.js.erb @@ -0,0 +1 @@ +$("#comments").html("<%= j render 'comment' %>"); diff --git a/app/views/comments/show.html.slim b/app/views/comments/show.html.slim new file mode 100644 index 0000000..268dd5e --- /dev/null +++ b/app/views/comments/show.html.slim @@ -0,0 +1 @@ += @comment.body diff --git a/app/views/favourites/_favourite.html.erb b/app/views/favourites/_favourite.html.erb new file mode 100644 index 0000000..45707b0 --- /dev/null +++ b/app/views/favourites/_favourite.html.erb @@ -0,0 +1,5 @@ +<% if user_favourite.present? %> + <%= link_to "Unfavourite", post_favourite_path(@post, user_favourite), method: :delete, remote: true, class: "glyphicon glyphicon-star" %> +<% else %> + <%= link_to "Favourite", post_favourites_path(@post), method: :post, remote: true, class: "glyphicon glyphicon-star-empty" %> +<% end %> diff --git a/app/views/favourites/index.html.slim b/app/views/favourites/index.html.slim new file mode 100644 index 0000000..5fa22d7 --- /dev/null +++ b/app/views/favourites/index.html.slim @@ -0,0 +1,5 @@ +h1 Your Favourite Products + +- @favourites.each do |favourite| + div + = link_to favourite.post.title, post_path(favourite.post) diff --git a/app/views/favourites/modify_favourite.js.erb b/app/views/favourites/modify_favourite.js.erb new file mode 100644 index 0000000..7bd22e5 --- /dev/null +++ b/app/views/favourites/modify_favourite.js.erb @@ -0,0 +1 @@ +$("#favourite").html("<%= j render 'favourite' %>"); diff --git a/app/views/home/about.html.erb b/app/views/home/about.html.erb new file mode 100644 index 0000000..e685f80 --- /dev/null +++ b/app/views/home/about.html.erb @@ -0,0 +1,4 @@ +
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi at purus ut velit placerat egestas ut a nibh. Pellentesque pulvinar, justo quis consequat vestibulum, sapien nisi bibendum est, et molestie leo tellus vitae erat. Maecenas sed bibendum enim. Cras in libero quis eros sollicitudin commodo ac et leo. Suspendisse venenatis metus a vestibulum gravida. Pellentesque fringilla augue vel eros fringilla, eu porta nulla lobortis. Sed porta ligula ut lacus accumsan, nec facilisis neque egestas.
diff --git a/app/views/home/home.html.erb b/app/views/home/home.html.erb new file mode 100644 index 0000000..fe1d011 --- /dev/null +++ b/app/views/home/home.html.erb @@ -0,0 +1 @@ +