From 0d3f795a05394ffa959295e3b7034ec109b9db39 Mon Sep 17 00:00:00 2001 From: Maggie Date: Wed, 6 Mar 2019 21:37:14 -0500 Subject: [PATCH 01/26] Add paginatio to index page --- .ruby-version | 2 +- Gemfile | 2 +- Gemfile.lock | 4 +++- app/controllers/dogs_controller.rb | 2 +- app/models/dog.rb | 2 ++ app/views/dogs/index.html.erb | 2 ++ 6 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.ruby-version b/.ruby-version index ab6d2789..79a61441 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.4.4 \ No newline at end of file +2.4.4 diff --git a/Gemfile b/Gemfile index 3f1e6961..90dcd8ef 100644 --- a/Gemfile +++ b/Gemfile @@ -35,7 +35,7 @@ gem 'jbuilder', '~> 2.5' gem 'devise' gem 'simple_form' - +gem 'will_paginate' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 16c3b7bc..23f38a3b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -220,6 +220,7 @@ GEM websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) + will_paginate (3.1.6) xpath (3.0.0) nokogiri (~> 1.8) @@ -249,9 +250,10 @@ DEPENDENCIES tzinfo-data uglifier (>= 1.3.0) web-console (>= 3.3.0) + will_paginate RUBY VERSION ruby 2.4.4p296 BUNDLED WITH - 1.16.2 + 2.0.1 diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index cb9eebc5..335e9995 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -4,7 +4,7 @@ class DogsController < ApplicationController # GET /dogs # GET /dogs.json def index - @dogs = Dog.all + @dogs = Dog.paginate(page: params[:page]) end # GET /dogs/1 diff --git a/app/models/dog.rb b/app/models/dog.rb index eb40bf6e..858d22bd 100644 --- a/app/models/dog.rb +++ b/app/models/dog.rb @@ -1,3 +1,5 @@ class Dog < ApplicationRecord has_many_attached :images + + self.per_page = 5 end diff --git a/app/views/dogs/index.html.erb b/app/views/dogs/index.html.erb index 91ea5603..1fb360c0 100644 --- a/app/views/dogs/index.html.erb +++ b/app/views/dogs/index.html.erb @@ -1 +1,3 @@ <%= render partial: 'thumbnail', collection: @dogs, as: :dog %> + +<%= will_paginate(@dogs) %> \ No newline at end of file From b324029498de940b37e4a0edc73ec7624266eb14 Mon Sep 17 00:00:00 2001 From: Maggie Date: Wed, 6 Mar 2019 22:18:17 -0500 Subject: [PATCH 02/26] Add multiple file ability feature --- README.md | 12 ++++++++++++ app/controllers/dogs_controller.rb | 2 +- app/views/dogs/_form.html.erb | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7e19680a..db8da51e 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,15 @@ Run the specs with `rspec` Run the server with `rails s` View the site at http://localhost:3000 + + +gem 'will_paginate' +@dogs = Dog.paginate(page: params[:page]) +<%= will_paginate(@dogs) %> + + +def dog_params + params.require(:dog).permit(:name, :description, images: []) + end + + <%= f.input :images, as: :file, :input_html => { :multiple => true } %> diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index 335e9995..e89277e7 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -73,6 +73,6 @@ def set_dog # Never trust parameters from the scary internet, only allow the white list through. def dog_params - params.require(:dog).permit(:name, :description, :images) + params.require(:dog).permit(:name, :description, images: []) end end diff --git a/app/views/dogs/_form.html.erb b/app/views/dogs/_form.html.erb index 6dfc7dc9..18a304de 100644 --- a/app/views/dogs/_form.html.erb +++ b/app/views/dogs/_form.html.erb @@ -1,7 +1,7 @@ <%= simple_form_for @dog do |f| %> <%= f.input :name %> <%= f.input :description, as: :text %> - <%= f.input :image, as: :file %> + <%= f.input :images, as: :file, :input_html => { :multiple => true } %> <% if @dog.images.any? %> <%= image_tag @dog.images.first %> From 9338e0af49e52a1d9d93e2f59f8edcf01e38d855 Mon Sep 17 00:00:00 2001 From: Maggie Date: Wed, 6 Mar 2019 22:29:52 -0500 Subject: [PATCH 03/26] Add dog associate with owners --- Gemfile | 1 + Gemfile.lock | 4 +++ app/models/dog.rb | 20 ++++++++++++++ app/models/user.rb | 27 +++++++++++++++++++ .../20190307032110_add_owner_idto_dogs.rb | 6 +++++ db/schema.rb | 4 ++- spec/factories/dogs.rb | 14 ++++++++++ 7 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190307032110_add_owner_idto_dogs.rb diff --git a/Gemfile b/Gemfile index 90dcd8ef..084caccf 100644 --- a/Gemfile +++ b/Gemfile @@ -36,6 +36,7 @@ gem 'jbuilder', '~> 2.5' gem 'devise' gem 'simple_form' gem 'will_paginate' +gem 'annotate' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 23f38a3b..d509a590 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,6 +44,9 @@ GEM tzinfo (~> 1.1) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) + annotate (2.7.4) + activerecord (>= 3.2, < 6.0) + rake (>= 10.4, < 13.0) arel (9.0.0) bcrypt (3.1.12) bindex (0.5.0) @@ -228,6 +231,7 @@ PLATFORMS ruby DEPENDENCIES + annotate bootsnap (>= 1.1.0) byebug capybara diff --git a/app/models/dog.rb b/app/models/dog.rb index 858d22bd..5b008152 100644 --- a/app/models/dog.rb +++ b/app/models/dog.rb @@ -1,5 +1,25 @@ +# == Schema Information +# +# Table name: dogs +# +# id :integer not null, primary key +# name :string +# birthday :datetime +# adoption_date :datetime +# description :text +# created_at :datetime not null +# updated_at :datetime not null +# owner_id :integer +# + class Dog < ApplicationRecord has_many_attached :images self.per_page = 5 + + belongs_to :owner, + primary_key: :id, + foreign_key: :owner_id, + class_name: 'User' + end diff --git a/app/models/user.rb b/app/models/user.rb index b2091f9a..ea2c06dd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,33 @@ +# == Schema Information +# +# Table name: users +# +# id :integer not null, primary key +# name :string +# email :string +# created_at :datetime not null +# updated_at :datetime not null +# encrypted_password :string default(""), not null +# reset_password_token :string +# reset_password_sent_at :datetime +# remember_created_at :datetime +# sign_in_count :integer default(0), not null +# current_sign_in_at :datetime +# last_sign_in_at :datetime +# current_sign_in_ip :string +# last_sign_in_ip :string +# + class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable + + has_many :dogs, + primary_key: :id, + foreign_key: :owner_id, + class_name: 'Dog', + dependent: :destroy + end diff --git a/db/migrate/20190307032110_add_owner_idto_dogs.rb b/db/migrate/20190307032110_add_owner_idto_dogs.rb new file mode 100644 index 00000000..18b3fd36 --- /dev/null +++ b/db/migrate/20190307032110_add_owner_idto_dogs.rb @@ -0,0 +1,6 @@ +class AddOwnerIdtoDogs < ActiveRecord::Migration[5.2] + def change + add_column :dogs, :owner_id, :integer + add_index :dogs, :owner_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 462bd430..c97054d9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_06_07_114248) do +ActiveRecord::Schema.define(version: 2019_03_07_032110) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false @@ -40,6 +40,8 @@ t.text "description" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "owner_id" + t.index ["owner_id"], name: "index_dogs_on_owner_id" end create_table "users", force: :cascade do |t| diff --git a/spec/factories/dogs.rb b/spec/factories/dogs.rb index 406874f5..a24818b8 100644 --- a/spec/factories/dogs.rb +++ b/spec/factories/dogs.rb @@ -1,3 +1,17 @@ +# == Schema Information +# +# Table name: dogs +# +# id :integer not null, primary key +# name :string +# birthday :datetime +# adoption_date :datetime +# description :text +# created_at :datetime not null +# updated_at :datetime not null +# owner_id :integer +# + FactoryBot.define do factory :dog do sequence :name do |n| From cd6dcfd3009557839f0d36bf406305dc7db7ffd9 Mon Sep 17 00:00:00 2001 From: Maggie Date: Wed, 6 Mar 2019 22:44:09 -0500 Subject: [PATCH 04/26] Allow editing only by owner --- app/controllers/dogs_controller.rb | 1 + app/models/dog.rb | 6 +++--- app/models/user.rb | 8 ++++---- app/views/dogs/show.html.erb | 4 +++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index e89277e7..7a2af2da 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -25,6 +25,7 @@ def edit # POST /dogs.json def create @dog = Dog.new(dog_params) + @dog.owner_id = current_user.id respond_to do |format| if @dog.save diff --git a/app/models/dog.rb b/app/models/dog.rb index 5b008152..2eb1833d 100644 --- a/app/models/dog.rb +++ b/app/models/dog.rb @@ -18,8 +18,8 @@ class Dog < ApplicationRecord self.per_page = 5 belongs_to :owner, - primary_key: :id, - foreign_key: :owner_id, - class_name: 'User' + primary_key: :id, + foreign_key: :owner_id, + class_name: 'User' end diff --git a/app/models/user.rb b/app/models/user.rb index ea2c06dd..b84136e4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -25,9 +25,9 @@ class User < ApplicationRecord :recoverable, :rememberable, :trackable, :validatable has_many :dogs, - primary_key: :id, - foreign_key: :owner_id, - class_name: 'Dog', - dependent: :destroy + primary_key: :id, + foreign_key: :owner_id, + class_name: 'Dog', + dependent: :destroy end diff --git a/app/views/dogs/show.html.erb b/app/views/dogs/show.html.erb index 562324d2..5a8c86b7 100644 --- a/app/views/dogs/show.html.erb +++ b/app/views/dogs/show.html.erb @@ -7,7 +7,9 @@

<%= @dog.description %>

- <%= link_to "Edit #{@dog.name}'s Profile", edit_dog_path %> + <% if current_user.id == @dog.owner_id %> + <%= link_to "Edit #{@dog.name}'s Profile", edit_dog_path %> + <% end %>
<%= link_to "Delete #{@dog.name}'s Profile", dog_path, method: :delete, data: { confirm: 'Are you sure?' } %> From aa54190dd507c9de357b2009e79d0280589cb4b4 Mon Sep 17 00:00:00 2001 From: Maggie Date: Thu, 7 Mar 2019 13:49:56 -0500 Subject: [PATCH 05/26] Add likes features and update seed file --- app/controllers/application_controller.rb | 3 ++ app/controllers/dogs_controller.rb | 4 +++ app/controllers/likes_controller.rb | 41 +++++++++++++++++++++++ app/models/dog.rb | 5 +++ app/models/like.rb | 25 ++++++++++++++ app/models/user.rb | 6 ++++ app/views/dogs/show.html.erb | 15 +++++++-- config/routes.rb | 6 +++- db/migrate/20190307153758_create_likes.rb | 14 ++++++++ db/schema.rb | 12 ++++++- db/seeds.rb | 7 +++- 11 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 app/controllers/likes_controller.rb create mode 100644 app/models/like.rb create mode 100644 db/migrate/20190307153758_create_likes.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d12..c0497456 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,5 @@ class ApplicationController < ActionController::Base + def require_login + redirect_to dogs_url unless current_user + end end diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index 7a2af2da..ec76534a 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -1,5 +1,6 @@ class DogsController < ApplicationController before_action :set_dog, only: [:show, :edit, :update, :destroy] + before_action :require_login, only: [:new, :create] # GET /dogs # GET /dogs.json @@ -10,6 +11,9 @@ def index # GET /dogs/1 # GET /dogs/1.json def show + if current_user + @like = Like.where(liker_id: current_user.id).where(dog_id: @dog.id)[0] + end end # GET /dogs/new diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb new file mode 100644 index 00000000..7618158e --- /dev/null +++ b/app/controllers/likes_controller.rb @@ -0,0 +1,41 @@ +class LikesController < ApplicationController + before_action :require_login + + # POST /dogs/:dog_id/likes + # POST /dogs.json + def create + @like = Like.new(like_params) + @like.liker_id = current_user.id + @like.dog_id = params[:dog_id] + + respond_to do |format| + if @like.save + @dog = Dog.find(params[:dog_id]) + + format.html { redirect_to @dog } + format.json { render :show, status: :created, location: @dog } + + else + format.json { render json: @like.errors.full_messages, status: 422 } + end + end + + end + + # DELETE /likes/1 + # DELETE /likes/1.json + def destroy + @like = Like.find(params[:id]) + @dog = Dog.find(@like.dog_id) + @like.destroy + + respond_to do |format| + format.html { redirect_to @dog } + end + end + + private + def like_params + params.permit(:dog_id, :liker_id) + end +end \ No newline at end of file diff --git a/app/models/dog.rb b/app/models/dog.rb index 2eb1833d..386339ef 100644 --- a/app/models/dog.rb +++ b/app/models/dog.rb @@ -21,5 +21,10 @@ class Dog < ApplicationRecord primary_key: :id, foreign_key: :owner_id, class_name: 'User' + + has_many :likes, + primary_key: :id, + foreign_key: :dog_id, + class_name: 'Like' end diff --git a/app/models/like.rb b/app/models/like.rb new file mode 100644 index 00000000..81090eb7 --- /dev/null +++ b/app/models/like.rb @@ -0,0 +1,25 @@ +# == Schema Information +# +# Table name: likes +# +# id :integer not null, primary key +# dog_id :integer not null +# liker_id :integer not null +# created_at :datetime not null +# updated_at :datetime not null +# + +class Like < ApplicationRecord + + belongs_to :liker, + primary_key: :id, + foreign_key: :liker_id, + class_name: 'User' + + belongs_to :dog, + primary_key: :id, + foreign_key: :dog_id, + class_name: 'Dog' + + +end diff --git a/app/models/user.rb b/app/models/user.rb index b84136e4..0ef531c9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -30,4 +30,10 @@ class User < ApplicationRecord class_name: 'Dog', dependent: :destroy + has_many :likes, + primary_key: :id, + foreign_key: :liker_id, + class_name: 'Like', + dependent: :destroy + end diff --git a/app/views/dogs/show.html.erb b/app/views/dogs/show.html.erb index 5a8c86b7..7067bef7 100644 --- a/app/views/dogs/show.html.erb +++ b/app/views/dogs/show.html.erb @@ -1,5 +1,16 @@

<%= @dog.name %>

+

Number of Likes: <%= @dog.likes.count %>

+ + <% if current_user %> + <% if @like %> + <%= link_to "Unlike", like_url(@like.id), method: :delete %> + <% else %> + <%= link_to "Like", dog_likes_url(@dog), method: :post %> + <% end %> + <% end %> + +
<% @dog.images.each do |image| %> <%= image_tag url_for(image), alt: "Photo of #{@dog.name}" %> @@ -7,9 +18,9 @@

<%= @dog.description %>

- <% if current_user.id == @dog.owner_id %> + <% if current_user && current_user.id == @dog.owner_id %> <%= link_to "Edit #{@dog.name}'s Profile", edit_dog_path %> + <%= link_to "Delete #{@dog.name}'s Profile", dog_path, method: :delete, data: { confirm: 'Are you sure?' } %> <% end %>
- <%= link_to "Delete #{@dog.name}'s Profile", dog_path, method: :delete, data: { confirm: 'Are you sure?' } %>
diff --git a/config/routes.rb b/config/routes.rb index 06b01adc..8f8c2edb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,10 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html devise_for :users - resources :dogs + resources :dogs do + resources :likes, only: [:create] + end + + resources :likes, only: [:destroy] root to: "dogs#index" end diff --git a/db/migrate/20190307153758_create_likes.rb b/db/migrate/20190307153758_create_likes.rb new file mode 100644 index 00000000..3e4566f1 --- /dev/null +++ b/db/migrate/20190307153758_create_likes.rb @@ -0,0 +1,14 @@ +class CreateLikes < ActiveRecord::Migration[5.2] + def change + create_table :likes do |t| + t.integer :dog_id, null: false + t.integer :liker_id, null: false + + t.timestamps + end + + add_index :likes, [:liker_id, :dog_id], unique: true + add_index :likes, :liker_id + add_index :likes, :dog_id + end +end diff --git a/db/schema.rb b/db/schema.rb index c97054d9..7744f421 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_03_07_032110) do +ActiveRecord::Schema.define(version: 2019_03_07_153758) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false @@ -44,6 +44,16 @@ t.index ["owner_id"], name: "index_dogs_on_owner_id" end + create_table "likes", force: :cascade do |t| + t.integer "dog_id", null: false + t.integer "liker_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["dog_id"], name: "index_likes_on_dog_id" + t.index ["liker_id", "dog_id"], name: "index_likes_on_liker_id_and_dog_id", unique: true + t.index ["liker_id"], name: "index_likes_on_liker_id" + end + create_table "users", force: :cascade do |t| t.string "name" t.string "email" diff --git a/db/seeds.rb b/db/seeds.rb index d3e6fde3..e7a4016e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,6 +6,9 @@ # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) +Dog.destroy_all +User.destroy_all + dogs = [ { name: 'Bowie', @@ -49,8 +52,10 @@ }, ] +default_owner = User.create!(email: 'maggie@gmail.com', password: 'starwars') + dogs.each do |dog| - dog = Dog.find_or_create_by(name: dog[:name], description: dog[:description]) + dog = Dog.find_or_create_by(name: dog[:name], description: dog[:description], owner_id: default_owner.id) directory_name = File.join(Rails.root, 'db', 'seed', "#{dog[:name].downcase}", "*") Dir.glob(directory_name).each do |filename| From b641827678fd74d9f3873be55c87df4442b684a0 Mon Sep 17 00:00:00 2001 From: Maggie Date: Fri, 8 Mar 2019 00:51:12 -0500 Subject: [PATCH 06/26] Add sort filter --- app/controllers/dogs_controller.rb | 19 ++++++++++++++++++- app/models/dog.rb | 2 -- app/models/like.rb | 2 ++ app/views/dogs/index.html.erb | 2 ++ app/views/dogs/show.html.erb | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index ec76534a..ed744229 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -5,7 +5,24 @@ class DogsController < ApplicationController # GET /dogs # GET /dogs.json def index - @dogs = Dog.paginate(page: params[:page]) + + if params[:sort_params] + # @dogs = Dog.paginate(page: params[:page], :per_page => 5) + # .left_outer_joins(:likes) + # .where('likes.created_at < ?', 1.hour.ago) + # .group('likes') + # .order("count(likes.id) desc") + @dogs = Dog.paginate(page: params[:page], :per_page => 5) + .left_outer_joins(:likes) + .group('dogs.id') + .order('count(likes.id) DESC') + # .merge(Like.filtered_likes) + # .select('dogs.*') + + + else + @dogs = Dog.paginate(page: params[:page], :per_page => 5) + end end # GET /dogs/1 diff --git a/app/models/dog.rb b/app/models/dog.rb index 386339ef..09aaf952 100644 --- a/app/models/dog.rb +++ b/app/models/dog.rb @@ -15,8 +15,6 @@ class Dog < ApplicationRecord has_many_attached :images - self.per_page = 5 - belongs_to :owner, primary_key: :id, foreign_key: :owner_id, diff --git a/app/models/like.rb b/app/models/like.rb index 81090eb7..cdb03ec4 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -11,6 +11,8 @@ class Like < ApplicationRecord + scope :filtered_likes, -> { where('created_at <= ?', 1.hour.ago) } + belongs_to :liker, primary_key: :id, foreign_key: :liker_id, diff --git a/app/views/dogs/index.html.erb b/app/views/dogs/index.html.erb index 1fb360c0..7ead232b 100644 --- a/app/views/dogs/index.html.erb +++ b/app/views/dogs/index.html.erb @@ -1,3 +1,5 @@ +<%= link_to "Sort By Likes", :controller => "dogs", :action => "index", :sort_params => true %> + <%= render partial: 'thumbnail', collection: @dogs, as: :dog %> <%= will_paginate(@dogs) %> \ No newline at end of file diff --git a/app/views/dogs/show.html.erb b/app/views/dogs/show.html.erb index 7067bef7..eeea84fe 100644 --- a/app/views/dogs/show.html.erb +++ b/app/views/dogs/show.html.erb @@ -2,7 +2,7 @@

<%= @dog.name %>

Number of Likes: <%= @dog.likes.count %>

- <% if current_user %> + <% if current_user && @dog.owner_id != current_user.id %> <% if @like %> <%= link_to "Unlike", like_url(@like.id), method: :delete %> <% else %> From 9e7e671b9617e41673bd6b3d2b59b865b3c075f2 Mon Sep 17 00:00:00 2001 From: Maggie Date: Fri, 8 Mar 2019 19:41:02 -0500 Subject: [PATCH 07/26] Update dogs controller to update sort query --- app/controllers/dogs_controller.rb | 22 +++++++--------------- app/models/like.rb | 4 +++- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index ed744229..73d71992 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -1,3 +1,4 @@ +require "time" class DogsController < ApplicationController before_action :set_dog, only: [:show, :edit, :update, :destroy] before_action :require_login, only: [:new, :create] @@ -5,21 +6,12 @@ class DogsController < ApplicationController # GET /dogs # GET /dogs.json def index - - if params[:sort_params] - # @dogs = Dog.paginate(page: params[:page], :per_page => 5) - # .left_outer_joins(:likes) - # .where('likes.created_at < ?', 1.hour.ago) - # .group('likes') - # .order("count(likes.id) desc") - @dogs = Dog.paginate(page: params[:page], :per_page => 5) - .left_outer_joins(:likes) - .group('dogs.id') - .order('count(likes.id) DESC') - # .merge(Like.filtered_likes) - # .select('dogs.*') - - + if params[:sort_params] + subquery = Like.select(:id, :dog_id, :user_id).where(created_at: (Time.now - 1.hour)..Time.now) + @dogs = Dog.paginate(page: params[:page], :per_page => 5) + .joins("LEFT JOIN (#{subquery.to_sql}) AS likes ON dogs.id = likes.dog_id") + .group(:id) + .order("count(likes.id) desc") else @dogs = Dog.paginate(page: params[:page], :per_page => 5) end diff --git a/app/models/like.rb b/app/models/like.rb index cdb03ec4..1b2a5a9e 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -11,7 +11,9 @@ class Like < ApplicationRecord - scope :filtered_likes, -> { where('created_at <= ?', 1.hour.ago) } + scope :filtered_likes, -> { where(created_at: (Time.now - 1.hour)..Time.now) } + + belongs_to :liker, primary_key: :id, From e1d287859f27592f03ef042ddcdb1436b4be3d6e Mon Sep 17 00:00:00 2001 From: Maggie Date: Fri, 8 Mar 2019 21:58:30 -0500 Subject: [PATCH 08/26] Add ad to index page --- app/views/dogs/_thumbnail.html.erb | 8 ++++++++ app/views/dogs/index.html.erb | 1 + 2 files changed, 9 insertions(+) diff --git a/app/views/dogs/_thumbnail.html.erb b/app/views/dogs/_thumbnail.html.erb index 4d6bb441..2f0bafaa 100644 --- a/app/views/dogs/_thumbnail.html.erb +++ b/app/views/dogs/_thumbnail.html.erb @@ -4,3 +4,11 @@ <%= image_tag url_for(dog.images.first), class: "dog-photo", alt: "Photo of #{dog.name}" %> + + +<% if dog_counter % 2 == 1 %> +
+

Collar for sale!

+ <%= image_tag image_url('ad.jpg'), class: "ad-photo", alt: "Photo of ad" %> +
+<% end %> diff --git a/app/views/dogs/index.html.erb b/app/views/dogs/index.html.erb index 7ead232b..fb08f138 100644 --- a/app/views/dogs/index.html.erb +++ b/app/views/dogs/index.html.erb @@ -2,4 +2,5 @@ <%= render partial: 'thumbnail', collection: @dogs, as: :dog %> + <%= will_paginate(@dogs) %> \ No newline at end of file From 0c87571c9870e51cb36a175685c93be89a211eec Mon Sep 17 00:00:00 2001 From: Maggie Date: Sat, 9 Mar 2019 11:22:59 -0500 Subject: [PATCH 09/26] Add carousel to dog show page --- Gemfile | 5 ++- Gemfile.lock | 15 +++++++++ app/assets/javascripts/application.js | 2 ++ .../{application.css => application.css.scss} | 3 ++ app/views/dogs/show.html.erb | 33 +++++++++++++++++-- 5 files changed, 54 insertions(+), 4 deletions(-) rename app/assets/stylesheets/{application.css => application.css.scss} (93%) diff --git a/Gemfile b/Gemfile index 084caccf..1f76afa7 100644 --- a/Gemfile +++ b/Gemfile @@ -32,10 +32,13 @@ gem 'jbuilder', '~> 2.5' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development - +gem 'jquery-rails' gem 'devise' gem 'simple_form' gem 'will_paginate' +gem 'bootstrap-sass' +gem 'autoprefixer-rails' + gem 'annotate' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false diff --git a/Gemfile.lock b/Gemfile.lock index d509a590..4608e4a4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,10 +48,15 @@ GEM activerecord (>= 3.2, < 6.0) rake (>= 10.4, < 13.0) arel (9.0.0) + autoprefixer-rails (9.4.10.2) + execjs bcrypt (3.1.12) bindex (0.5.0) bootsnap (1.3.0) msgpack (~> 1.0) + bootstrap-sass (3.4.1) + autoprefixer-rails (>= 5.2.1) + sassc (>= 2.0.0) builder (3.2.3) byebug (10.0.2) capybara (2.18.0) @@ -93,6 +98,10 @@ GEM jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) + jquery-rails (4.3.3) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -187,6 +196,9 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + sassc (2.0.1) + ffi (~> 1.9) + rake simple_form (4.0.1) actionpack (>= 5.0) activemodel (>= 5.0) @@ -232,13 +244,16 @@ PLATFORMS DEPENDENCIES annotate + autoprefixer-rails bootsnap (>= 1.1.0) + bootstrap-sass byebug capybara coffee-rails (~> 4.2) devise factory_bot_rails jbuilder (~> 2.5) + jquery-rails listen (>= 3.0.5, < 3.2) pry puma (~> 3.11) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 2ca2b461..143d69f4 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,9 +10,11 @@ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // +//= require jquery //= require rails-ujs //= require activestorage //= require turbolinks +//= require bootstrap-sprockets //= require_tree . console.log('Welcome!'); diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css.scss similarity index 93% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.css.scss index edb771d6..9969f4d2 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css.scss @@ -13,9 +13,12 @@ *= require_tree . *= require_self */ +@import "bootstrap-sprockets"; +@import "bootstrap"; header { align-items: center; display: flex; justify-content: space-between; } + diff --git a/app/views/dogs/show.html.erb b/app/views/dogs/show.html.erb index eeea84fe..408a9974 100644 --- a/app/views/dogs/show.html.erb +++ b/app/views/dogs/show.html.erb @@ -12,9 +12,36 @@
- <% @dog.images.each do |image| %> - <%= image_tag url_for(image), alt: "Photo of #{@dog.name}" %> - <% end %> + + + +

<%= @dog.description %>

From c23b2142356d26f5c411138a34f8e350b5b18702 Mon Sep 17 00:00:00 2001 From: Maggie Date: Sat, 9 Mar 2019 12:58:11 -0500 Subject: [PATCH 10/26] Add css to show page --- app/assets/stylesheets/application.css.scss | 63 +++++++++++++++++++++ app/views/dogs/show.html.erb | 14 ++++- 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 9969f4d2..d79cd39c 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -22,3 +22,66 @@ header { justify-content: space-between; } +.dog-description { + text-align: center; +} + +.item { + height: 300px; +} +.item > img { + object-fit: cover; + width: 300px; + height: 300px; + margin: 0 auto; +} + +.thumbnail-container { + margin: 0 auto; + max-width: 1200px; + padding: 0 1rem; +} + +.thumbnail-image { + height: 300px; + width: 300px; + object-fit: cover; + max-width: 100%; +} + +.thumbnail-cell img { + display: block; +} + +@media screen and (min-width: 600px) { + .thumbnail-grid { + display: flex; + flex-wrap: wrap; + flex-direction: row; + } + .thumbnail-cell { + width: 50%; + } +} + +@media screen and (min-width: 1000px) { + .thumbnail-cell { + width: calc(100% / 3); + } +} + +.thumbnail-cell { + margin: 1rem; +} + +@media screen and (min-width: 600px) { + .thumbnail-cell { + width: calc(50% - 2rem); + } +} + +@media screen and (min-width: 1000px) { + .thumbnail-cell { + width: calc(33.3333% - 2rem); + } +} \ No newline at end of file diff --git a/app/views/dogs/show.html.erb b/app/views/dogs/show.html.erb index 408a9974..04c43b2c 100644 --- a/app/views/dogs/show.html.erb +++ b/app/views/dogs/show.html.erb @@ -41,9 +41,17 @@ - - -

<%= @dog.description %>

+

<%= @dog.description %>

+ +
+
+ <% @dog.images.each do |image| %> +
+ <%= image_tag url_for(image), class: "thumbnail-image", alt: "Photo of #{@dog.name}" %> +
+ <% end %> +
+
<% if current_user && current_user.id == @dog.owner_id %> <%= link_to "Edit #{@dog.name}'s Profile", edit_dog_path %> From 14f6d5c84152098071c0cfd289ea2483c71a1a6d Mon Sep 17 00:00:00 2001 From: Maggie Date: Sat, 9 Mar 2019 20:49:19 -0500 Subject: [PATCH 11/26] Update css --- app/assets/stylesheets/application.css.scss | 50 --------------------- app/views/dogs/_thumbnail.html.erb | 19 +++++--- app/views/dogs/show.html.erb | 10 ----- 3 files changed, 12 insertions(+), 67 deletions(-) diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index d79cd39c..63a14a69 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -34,54 +34,4 @@ header { width: 300px; height: 300px; margin: 0 auto; -} - -.thumbnail-container { - margin: 0 auto; - max-width: 1200px; - padding: 0 1rem; -} - -.thumbnail-image { - height: 300px; - width: 300px; - object-fit: cover; - max-width: 100%; -} - -.thumbnail-cell img { - display: block; -} - -@media screen and (min-width: 600px) { - .thumbnail-grid { - display: flex; - flex-wrap: wrap; - flex-direction: row; - } - .thumbnail-cell { - width: 50%; - } -} - -@media screen and (min-width: 1000px) { - .thumbnail-cell { - width: calc(100% / 3); - } -} - -.thumbnail-cell { - margin: 1rem; -} - -@media screen and (min-width: 600px) { - .thumbnail-cell { - width: calc(50% - 2rem); - } -} - -@media screen and (min-width: 1000px) { - .thumbnail-cell { - width: calc(33.3333% - 2rem); - } } \ No newline at end of file diff --git a/app/views/dogs/_thumbnail.html.erb b/app/views/dogs/_thumbnail.html.erb index 2f0bafaa..3d0c6284 100644 --- a/app/views/dogs/_thumbnail.html.erb +++ b/app/views/dogs/_thumbnail.html.erb @@ -1,10 +1,15 @@ - -
-

<%= dog.name %>

- <%= image_tag url_for(dog.images.first), class: "dog-photo", alt: "Photo of #{dog.name}" %> -
-
- + <% if dog_counter % 2 == 1 %>
diff --git a/app/views/dogs/show.html.erb b/app/views/dogs/show.html.erb index 04c43b2c..b97e0b66 100644 --- a/app/views/dogs/show.html.erb +++ b/app/views/dogs/show.html.erb @@ -43,16 +43,6 @@

<%= @dog.description %>

-
-
- <% @dog.images.each do |image| %> -
- <%= image_tag url_for(image), class: "thumbnail-image", alt: "Photo of #{@dog.name}" %> -
- <% end %> -
-
- <% if current_user && current_user.id == @dog.owner_id %> <%= link_to "Edit #{@dog.name}'s Profile", edit_dog_path %> <%= link_to "Delete #{@dog.name}'s Profile", dog_path, method: :delete, data: { confirm: 'Are you sure?' } %> From a5c7cab59b7d0c6e4a5b74edc942acf8b8d39d45 Mon Sep 17 00:00:00 2001 From: Maggie Date: Sat, 9 Mar 2019 21:14:27 -0500 Subject: [PATCH 12/26] Update home page responsive grid layout --- app/assets/stylesheets/application.css.scss | 6 ++++++ app/views/dogs/_thumbnail.html.erb | 18 +++++++++--------- app/views/dogs/index.html.erb | 7 +++++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 63a14a69..6eb386b8 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -34,4 +34,10 @@ header { width: 300px; height: 300px; margin: 0 auto; +} + +.dog-photo, .ad-photo { + height: 300px; + width: 300px; + object-fit: cover; } \ No newline at end of file diff --git a/app/views/dogs/_thumbnail.html.erb b/app/views/dogs/_thumbnail.html.erb index 3d0c6284..9f782ce0 100644 --- a/app/views/dogs/_thumbnail.html.erb +++ b/app/views/dogs/_thumbnail.html.erb @@ -1,6 +1,5 @@ -
- + <% if dog_counter % 2 == 1 %> -
-

Collar for sale!

- <%= image_tag image_url('ad.jpg'), class: "ad-photo", alt: "Photo of ad" %> -
+
+
+

Collar for sale!

+ <%= image_tag image_url('ad.jpg'), class: "ad-photo", alt: "Photo of ad" %> +
+
<% end %> diff --git a/app/views/dogs/index.html.erb b/app/views/dogs/index.html.erb index fb08f138..da78ff23 100644 --- a/app/views/dogs/index.html.erb +++ b/app/views/dogs/index.html.erb @@ -1,6 +1,9 @@ <%= link_to "Sort By Likes", :controller => "dogs", :action => "index", :sort_params => true %> -<%= render partial: 'thumbnail', collection: @dogs, as: :dog %> - +
+
+ <%= render partial: 'thumbnail', collection: @dogs, as: :dog %> +
+
<%= will_paginate(@dogs) %> \ No newline at end of file From 91630359deed4eb6615649833445f1f9a0b2ca74 Mon Sep 17 00:00:00 2001 From: Maggie Date: Sat, 9 Mar 2019 23:45:24 -0500 Subject: [PATCH 13/26] Update page links --- Gemfile | 1 + Gemfile.lock | 9 +++++++++ app/views/dogs/_dogs.html.erb | 12 ++++++++++++ app/views/dogs/index.html.erb | 14 +++++++------- app/views/dogs/index.js.erb | 2 ++ 5 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 app/views/dogs/_dogs.html.erb create mode 100644 app/views/dogs/index.js.erb diff --git a/Gemfile b/Gemfile index 1f76afa7..5dd0314e 100644 --- a/Gemfile +++ b/Gemfile @@ -36,6 +36,7 @@ gem 'jquery-rails' gem 'devise' gem 'simple_form' gem 'will_paginate' +gem 'will_paginate-bootstrap' gem 'bootstrap-sass' gem 'autoprefixer-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 4608e4a4..b430d840 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,6 +102,7 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + libv8 (3.16.14.19) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -164,6 +165,7 @@ GEM rb-fsevent (0.10.3) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) + ref (2.0.0) responders (2.4.0) actionpack (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3) @@ -215,6 +217,9 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) + therubyracer (0.12.3) + libv8 (~> 3.16.14.15) + ref thor (0.20.0) thread_safe (0.3.6) tilt (2.0.8) @@ -236,6 +241,8 @@ GEM websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) will_paginate (3.1.6) + will_paginate-bootstrap (1.0.2) + will_paginate (>= 3.0.3) xpath (3.0.0) nokogiri (~> 1.8) @@ -265,11 +272,13 @@ DEPENDENCIES spring spring-watcher-listen (~> 2.0.0) sqlite3 + therubyracer turbolinks (~> 5) tzinfo-data uglifier (>= 1.3.0) web-console (>= 3.3.0) will_paginate + will_paginate-bootstrap RUBY VERSION ruby 2.4.4p296 diff --git a/app/views/dogs/_dogs.html.erb b/app/views/dogs/_dogs.html.erb new file mode 100644 index 00000000..b55d3e88 --- /dev/null +++ b/app/views/dogs/_dogs.html.erb @@ -0,0 +1,12 @@ +<%= link_to "Sort By Likes", :controller => "dogs", :action => "index", :sort_params => true %> + +
+
+ <%= render partial: 'thumbnail', collection: @dogs, as: :dog %> +
+ +
+ + diff --git a/app/views/dogs/index.html.erb b/app/views/dogs/index.html.erb index da78ff23..add9c0e9 100644 --- a/app/views/dogs/index.html.erb +++ b/app/views/dogs/index.html.erb @@ -1,9 +1,9 @@ -<%= link_to "Sort By Likes", :controller => "dogs", :action => "index", :sort_params => true %> - -
-
- <%= render partial: 'thumbnail', collection: @dogs, as: :dog %> -
+
+ <%= render "dogs" %>
-<%= will_paginate(@dogs) %> \ No newline at end of file + diff --git a/app/views/dogs/index.js.erb b/app/views/dogs/index.js.erb new file mode 100644 index 00000000..bc3774e8 --- /dev/null +++ b/app/views/dogs/index.js.erb @@ -0,0 +1,2 @@ +$("#dogs").html('<%= escape_javascript(render 'dogs') %>'); +$('.pagination a').attr('data-remote', 'true'); From c76d11e7eec8a6cda7ef3057a7c1b3f3c58d75ce Mon Sep 17 00:00:00 2001 From: Maggie Date: Sat, 9 Mar 2019 23:52:09 -0500 Subject: [PATCH 14/26] Update ad description --- app/views/dogs/_dogs.html.erb | 9 +++++---- app/views/dogs/_thumbnail.html.erb | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/views/dogs/_dogs.html.erb b/app/views/dogs/_dogs.html.erb index b55d3e88..b3dc2bc1 100644 --- a/app/views/dogs/_dogs.html.erb +++ b/app/views/dogs/_dogs.html.erb @@ -1,12 +1,13 @@ -<%= link_to "Sort By Likes", :controller => "dogs", :action => "index", :sort_params => true %> +
+<%= link_to "Sort By Likes", :controller => "dogs", :action => "index", :sort_params => true %>
<%= render partial: 'thumbnail', collection: @dogs, as: :dog %>
- -
- + +
+ diff --git a/app/views/dogs/_thumbnail.html.erb b/app/views/dogs/_thumbnail.html.erb index 9f782ce0..fd25318b 100644 --- a/app/views/dogs/_thumbnail.html.erb +++ b/app/views/dogs/_thumbnail.html.erb @@ -12,7 +12,7 @@ <% if dog_counter % 2 == 1 %>
-

Collar for sale!

+

Collar for Sale!

<%= image_tag image_url('ad.jpg'), class: "ad-photo", alt: "Photo of ad" %>
From 4a4342e87cb4fcc83c84e98560223293bcbec817 Mon Sep 17 00:00:00 2001 From: Maggie Date: Sun, 10 Mar 2019 16:17:39 -0400 Subject: [PATCH 15/26] Add css to index and show pages --- Gemfile | 4 +- Gemfile.lock | 15 ++-- ...{application.css.scss => application.scss} | 9 ++ app/views/dogs/_dogs.html.erb | 8 +- app/views/dogs/_thumbnail.html.erb | 18 ++-- app/views/dogs/index.html.erb | 2 +- app/views/dogs/show.html.erb | 87 +++++++++---------- app/views/layouts/application.html.erb | 39 ++++++--- 8 files changed, 106 insertions(+), 76 deletions(-) rename app/assets/stylesheets/{application.css.scss => application.scss} (93%) diff --git a/Gemfile b/Gemfile index 5dd0314e..8bbcd480 100644 --- a/Gemfile +++ b/Gemfile @@ -32,12 +32,14 @@ gem 'jbuilder', '~> 2.5' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development + gem 'jquery-rails' gem 'devise' gem 'simple_form' gem 'will_paginate' gem 'will_paginate-bootstrap' -gem 'bootstrap-sass' +gem 'bootstrap-sass', '~> 3.4.1' +gem 'sassc-rails', '>= 2.1.0' gem 'autoprefixer-rails' gem 'annotate' diff --git a/Gemfile.lock b/Gemfile.lock index b430d840..7eab908c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,7 +102,6 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - libv8 (3.16.14.19) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -165,7 +164,6 @@ GEM rb-fsevent (0.10.3) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) - ref (2.0.0) responders (2.4.0) actionpack (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3) @@ -201,6 +199,12 @@ GEM sassc (2.0.1) ffi (~> 1.9) rake + sassc-rails (2.1.0) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt simple_form (4.0.1) actionpack (>= 5.0) activemodel (>= 5.0) @@ -217,9 +221,6 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) - therubyracer (0.12.3) - libv8 (~> 3.16.14.15) - ref thor (0.20.0) thread_safe (0.3.6) tilt (2.0.8) @@ -253,7 +254,7 @@ DEPENDENCIES annotate autoprefixer-rails bootsnap (>= 1.1.0) - bootstrap-sass + bootstrap-sass (~> 3.4.1) byebug capybara coffee-rails (~> 4.2) @@ -268,11 +269,11 @@ DEPENDENCIES rails-controller-testing rspec-rails (~> 3.7) sass-rails (~> 5.0) + sassc-rails (>= 2.1.0) simple_form spring spring-watcher-listen (~> 2.0.0) sqlite3 - therubyracer turbolinks (~> 5) tzinfo-data uglifier (>= 1.3.0) diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.scss similarity index 93% rename from app/assets/stylesheets/application.css.scss rename to app/assets/stylesheets/application.scss index 6eb386b8..c6435919 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.scss @@ -29,6 +29,7 @@ header { .item { height: 300px; } + .item > img { object-fit: cover; width: 300px; @@ -40,4 +41,12 @@ header { height: 300px; width: 300px; object-fit: cover; +} + +.pt-8 { + padding-top: 8rem !important; +} + +.text-large { + font-size: 150%; } \ No newline at end of file diff --git a/app/views/dogs/_dogs.html.erb b/app/views/dogs/_dogs.html.erb index b3dc2bc1..6f6a9830 100644 --- a/app/views/dogs/_dogs.html.erb +++ b/app/views/dogs/_dogs.html.erb @@ -1,7 +1,7 @@ - - -
-<%= link_to "Sort By Likes", :controller => "dogs", :action => "index", :sort_params => true %> +
+
+ <%= link_to "Sort By Likes", :controller => "dogs", :action => "index", :sort_params => true %> +
<%= render partial: 'thumbnail', collection: @dogs, as: :dog %>
diff --git a/app/views/dogs/_thumbnail.html.erb b/app/views/dogs/_thumbnail.html.erb index fd25318b..9b426913 100644 --- a/app/views/dogs/_thumbnail.html.erb +++ b/app/views/dogs/_thumbnail.html.erb @@ -1,16 +1,16 @@ - + <% if dog_counter % 2 == 1 %> -
+

Collar for Sale!

<%= image_tag image_url('ad.jpg'), class: "ad-photo", alt: "Photo of ad" %> diff --git a/app/views/dogs/index.html.erb b/app/views/dogs/index.html.erb index add9c0e9..0748cb62 100644 --- a/app/views/dogs/index.html.erb +++ b/app/views/dogs/index.html.erb @@ -1,4 +1,4 @@ -
+
<%= render "dogs" %>
diff --git a/app/views/dogs/show.html.erb b/app/views/dogs/show.html.erb index b97e0b66..97c553e4 100644 --- a/app/views/dogs/show.html.erb +++ b/app/views/dogs/show.html.erb @@ -1,51 +1,50 @@ -
-

<%= @dog.name %>

-

Number of Likes: <%= @dog.likes.count %>

- - <% if current_user && @dog.owner_id != current_user.id %> - <% if @like %> - <%= link_to "Unlike", like_url(@like.id), method: :delete %> - <% else %> - <%= link_to "Like", dog_likes_url(@dog), method: :post %> - <% end %> - <% end %> - +
+

<%= @dog.name %>


-
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d4bfefcd..0e8e58ba 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,21 +7,40 @@ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track": "reload" %> <%= javascript_include_tag "application", "data-turbolinks-track": "reload" %> + + + +
-

<%= link_to 'Dog Profile Demo', root_path %>

-
- <% if current_user %> - <%= link_to 'Add your dog', new_dog_path %> - <%= link_to 'Sign out', destroy_user_session_path, method: :delete %> - <% else %> - <%= link_to 'Sign in', new_user_session_path %> - <%= link_to 'Sign up', new_user_registration_path %> - <% end %> -
+
From b0ce7e6d58e822551f10ebe4101dcb0e6d1cd717 Mon Sep 17 00:00:00 2001 From: Maggie Date: Sun, 10 Mar 2019 16:19:13 -0400 Subject: [PATCH 16/26] Fix readme issue --- README.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/README.md b/README.md index db8da51e..4e05a406 100644 --- a/README.md +++ b/README.md @@ -18,14 +18,3 @@ Run the server with `rails s` View the site at http://localhost:3000 - -gem 'will_paginate' -@dogs = Dog.paginate(page: params[:page]) -<%= will_paginate(@dogs) %> - - -def dog_params - params.require(:dog).permit(:name, :description, images: []) - end - - <%= f.input :images, as: :file, :input_html => { :multiple => true } %> From f28b44ceb0d103951d8985ecd3334a0e370318ff Mon Sep 17 00:00:00 2001 From: Maggie Date: Sun, 10 Mar 2019 16:31:32 -0400 Subject: [PATCH 17/26] Update css for new page --- app/assets/stylesheets/application.scss | 4 ++++ app/views/dogs/_form.html.erb | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index c6435919..abf56f8e 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -43,6 +43,10 @@ header { object-fit: cover; } +.pt-6 { + padding-top: 5rem !important; +} + .pt-8 { padding-top: 8rem !important; } diff --git a/app/views/dogs/_form.html.erb b/app/views/dogs/_form.html.erb index 18a304de..54b6e4b0 100644 --- a/app/views/dogs/_form.html.erb +++ b/app/views/dogs/_form.html.erb @@ -1,7 +1,13 @@ -<%= simple_form_for @dog do |f| %> +<%= simple_form_for(@dog, html: { class: 'pt-6' }) do |f| %> +
<%= f.input :name %> +
+
<%= f.input :description, as: :text %> +
+
<%= f.input :images, as: :file, :input_html => { :multiple => true } %> +
<% if @dog.images.any? %> <%= image_tag @dog.images.first %> From 6d25a2041f460bc83a7bac4269859b049e5d85cb Mon Sep 17 00:00:00 2001 From: Maggie Date: Sun, 10 Mar 2019 17:00:21 -0400 Subject: [PATCH 18/26] Update css for new dog page --- app/models/dog.rb | 1 + app/views/dogs/_form.html.erb | 35 ++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/models/dog.rb b/app/models/dog.rb index 09aaf952..79cd1396 100644 --- a/app/models/dog.rb +++ b/app/models/dog.rb @@ -13,6 +13,7 @@ # class Dog < ApplicationRecord + has_many_attached :images belongs_to :owner, diff --git a/app/views/dogs/_form.html.erb b/app/views/dogs/_form.html.erb index 54b6e4b0..57595944 100644 --- a/app/views/dogs/_form.html.erb +++ b/app/views/dogs/_form.html.erb @@ -1,17 +1,22 @@ -<%= simple_form_for(@dog, html: { class: 'pt-6' }) do |f| %> -
- <%= f.input :name %> -
-
- <%= f.input :description, as: :text %> -
-
- <%= f.input :images, as: :file, :input_html => { :multiple => true } %> -
- <% if @dog.images.any? %> - <%= image_tag @dog.images.first %> - <% end %> +
+ <%= simple_form_for(@dog, html: { class: 'pt-6' }) do |f| %> +
+ <%= f.input :name, input_html: { class: 'form-control', required: true } %> +
+
+ <%= f.input :description, as: :text, input_html: { class: 'form-control' } %> +
+
+ <%= f.input :images, as: :file, :input_html => { :multiple => true } %> +
+ + <% if @dog.images.any? %> + <%= image_tag @dog.images.first %> + <% end %> - <%= f.button :submit %> -<% end %> +
+ <%= f.button :submit, :class => 'btn btn-primary' %> +
+ <% end %> +
From 18986917357eb1815ee67224b0fc3fa1bd9230bd Mon Sep 17 00:00:00 2001 From: Maggie Date: Sun, 10 Mar 2019 18:28:20 -0400 Subject: [PATCH 19/26] Add requirement for a dog photo --- Gemfile | 1 + Gemfile.lock | 1 + app/assets/javascripts/submit_button_disabled.js | 13 +++++++++++++ app/views/dogs/_form.html.erb | 9 +++++---- config/initializers/assets.rb | 2 ++ 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/submit_button_disabled.js diff --git a/Gemfile b/Gemfile index 8bbcd480..8fd3d379 100644 --- a/Gemfile +++ b/Gemfile @@ -41,6 +41,7 @@ gem 'will_paginate-bootstrap' gem 'bootstrap-sass', '~> 3.4.1' gem 'sassc-rails', '>= 2.1.0' gem 'autoprefixer-rails' +gem 'sprockets-rails' gem 'annotate' # Reduces boot times through caching; required in config/boot.rb diff --git a/Gemfile.lock b/Gemfile.lock index 7eab908c..ca24a3f3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -273,6 +273,7 @@ DEPENDENCIES simple_form spring spring-watcher-listen (~> 2.0.0) + sprockets-rails sqlite3 turbolinks (~> 5) tzinfo-data diff --git a/app/assets/javascripts/submit_button_disabled.js b/app/assets/javascripts/submit_button_disabled.js new file mode 100644 index 00000000..3d8ac6a0 --- /dev/null +++ b/app/assets/javascripts/submit_button_disabled.js @@ -0,0 +1,13 @@ +$(document).ready( + function () { + $('input:submit').attr('disabled', true); + $('input:file').change( + function () { + if ($(this).val()) { + $('input:submit').prop('disabled', false); + } + else { + $('input:submit').prop('disabled', true); + } + }); + }); diff --git a/app/views/dogs/_form.html.erb b/app/views/dogs/_form.html.erb index 57595944..947c71e6 100644 --- a/app/views/dogs/_form.html.erb +++ b/app/views/dogs/_form.html.erb @@ -1,14 +1,15 @@ +<%= javascript_include_tag 'submit_button_disabled.js' %>
- <%= simple_form_for(@dog, html: { class: 'pt-6' }) do |f| %> + <%= simple_form_for(@dog, html: { name:'myForm', class: 'pt-6' }) do |f| %>
- <%= f.input :name, input_html: { class: 'form-control', required: true } %> + <%= f.input :name, id: 'dog_upload', input_html: { class: 'form-control' } %>
<%= f.input :description, as: :text, input_html: { class: 'form-control' } %>
- <%= f.input :images, as: :file, :input_html => { :multiple => true } %> + <%= f.input :images, as: :file, required: true, :input_html => { :multiple => true } %>
<% if @dog.images.any? %> @@ -16,7 +17,7 @@ <% end %>
- <%= f.button :submit, :class => 'btn btn-primary' %> + <%= f.button :submit, :id => 'submit_button', :class => 'btn btn-primary', :disabled => true %>
<% end %>
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 4b828e80..abea4264 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -12,3 +12,5 @@ # application.js, application.css, and all non-JS/CSS in the app/assets # folder are already added. # Rails.application.config.assets.precompile += %w( admin.js admin.css ) + +Rails.application.config.assets.precompile += %w( submit_button_disabled.js ) \ No newline at end of file From 0a463980e081f8a563ff18311d96e5153a331a75 Mon Sep 17 00:00:00 2001 From: Maggie Date: Tue, 19 Mar 2019 15:22:12 -0400 Subject: [PATCH 20/26] Update rspecs --- Gemfile | 1 + Gemfile.lock | 3 +++ .../javascripts/submit_button_disabled.js | 13 ------------- app/assets/stylesheets/application.scss | 4 ++++ app/models/dog.rb | 2 +- app/views/dogs/_form.html.erb | 6 ++---- app/views/dogs/index.html.erb | 2 +- app/views/dogs/new.html.erb | 2 +- app/views/dogs/show.html.erb | 2 +- app/views/layouts/application.html.erb | 2 +- spec/features/dog_resource_spec.rb | 19 ++++++++++++++++--- spec/rails_helper.rb | 2 +- spec/spec_helper.rb | 2 +- spec/support/devise_helper.rb | 16 ++++++++++++++++ 14 files changed, 49 insertions(+), 27 deletions(-) delete mode 100644 app/assets/javascripts/submit_button_disabled.js create mode 100644 spec/support/devise_helper.rb diff --git a/Gemfile b/Gemfile index 8fd3d379..7d199809 100644 --- a/Gemfile +++ b/Gemfile @@ -53,6 +53,7 @@ group :development, :test do gem 'rspec-rails', '~> 3.7' gem 'factory_bot_rails' gem 'capybara' + gem 'launchy' gem 'pry' gem 'rails-controller-testing' end diff --git a/Gemfile.lock b/Gemfile.lock index ca24a3f3..b890a88a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,6 +102,8 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + launchy (2.4.3) + addressable (~> 2.3) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -262,6 +264,7 @@ DEPENDENCIES factory_bot_rails jbuilder (~> 2.5) jquery-rails + launchy listen (>= 3.0.5, < 3.2) pry puma (~> 3.11) diff --git a/app/assets/javascripts/submit_button_disabled.js b/app/assets/javascripts/submit_button_disabled.js deleted file mode 100644 index 3d8ac6a0..00000000 --- a/app/assets/javascripts/submit_button_disabled.js +++ /dev/null @@ -1,13 +0,0 @@ -$(document).ready( - function () { - $('input:submit').attr('disabled', true); - $('input:file').change( - function () { - if ($(this).val()) { - $('input:submit').prop('disabled', false); - } - else { - $('input:submit').prop('disabled', true); - } - }); - }); diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index abf56f8e..216ff6a4 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -53,4 +53,8 @@ header { .text-large { font-size: 150%; +} + +.form-title { + margin: auto; } \ No newline at end of file diff --git a/app/models/dog.rb b/app/models/dog.rb index 79cd1396..bb1eef86 100644 --- a/app/models/dog.rb +++ b/app/models/dog.rb @@ -16,7 +16,7 @@ class Dog < ApplicationRecord has_many_attached :images - belongs_to :owner, + belongs_to :owner, optional: true, primary_key: :id, foreign_key: :owner_id, class_name: 'User' diff --git a/app/views/dogs/_form.html.erb b/app/views/dogs/_form.html.erb index 947c71e6..8c81475a 100644 --- a/app/views/dogs/_form.html.erb +++ b/app/views/dogs/_form.html.erb @@ -1,5 +1,3 @@ -<%= javascript_include_tag 'submit_button_disabled.js' %> -
<%= simple_form_for(@dog, html: { name:'myForm', class: 'pt-6' }) do |f| %>
@@ -9,7 +7,7 @@ <%= f.input :description, as: :text, input_html: { class: 'form-control' } %>
- <%= f.input :images, as: :file, required: true, :input_html => { :multiple => true } %> + <%= f.input :images, as: :file, :input_html => { :multiple => true } %>
<% if @dog.images.any? %> @@ -17,7 +15,7 @@ <% end %>
- <%= f.button :submit, :id => 'submit_button', :class => 'btn btn-primary', :disabled => true %> + <%= f.button :submit, :id => 'submit_button', :class => 'btn btn-primary' %>
<% end %>
diff --git a/app/views/dogs/index.html.erb b/app/views/dogs/index.html.erb index 0748cb62..60dd6984 100644 --- a/app/views/dogs/index.html.erb +++ b/app/views/dogs/index.html.erb @@ -1,4 +1,4 @@ -
+
<%= render "dogs" %>
diff --git a/app/views/dogs/new.html.erb b/app/views/dogs/new.html.erb index 11dea8d6..4627cd3c 100644 --- a/app/views/dogs/new.html.erb +++ b/app/views/dogs/new.html.erb @@ -1,2 +1,2 @@ -

Add Your Dog

+

Add Your Dog

<%= render partial: 'form' %> diff --git a/app/views/dogs/show.html.erb b/app/views/dogs/show.html.erb index 97c553e4..7ac3d62a 100644 --- a/app/views/dogs/show.html.erb +++ b/app/views/dogs/show.html.erb @@ -1,4 +1,4 @@ -
+

<%= @dog.name %>


diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 0e8e58ba..9a48549a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -16,7 +16,7 @@
-
-
-
-

<%= notice %>

-

<%= alert %>

+ +
+
+
+

<%= notice %>

+

<%= alert %>

+
+ <%= yield %>
- <%= yield %>
+
From 171cebe7d7c54b01290163f52157e90eceb55a0b Mon Sep 17 00:00:00 2001 From: Maggie Date: Tue, 19 Mar 2019 15:43:40 -0400 Subject: [PATCH 22/26] Update dog show page css --- app/assets/stylesheets/application.scss | 4 ++++ app/views/layouts/application.html.erb | 14 +++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 216ff6a4..cf84c56e 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -57,4 +57,8 @@ header { .form-title { margin: auto; +} + +.carousel-indicators > li { + display: none; } \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9ef7779a..9a48549a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -42,17 +42,13 @@
- -
-
-
-

<%= notice %>

-

<%= alert %>

-
- <%= yield %> +
+
+

<%= notice %>

+

<%= alert %>

+ <%= yield %>
-
From 945992f08995946e1c8ab804ba5febc943f04350 Mon Sep 17 00:00:00 2001 From: Maggie Date: Tue, 19 Mar 2019 22:24:09 -0400 Subject: [PATCH 23/26] Update ReadMe --- README.md | 244 ++++++++++++++++++++++++ app/assets/stylesheets/application.scss | 8 +- app/views/dogs/_dogs.html.erb | 7 +- app/views/dogs/show.html.erb | 18 +- 4 files changed, 263 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4e05a406..a7374832 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,247 @@ Run the server with `rails s` View the site at http://localhost:3000 +# Backend + +## Add pagination to index page, to display 5 dogs per page + +app/controllers/dogs_controller.rb + +```ruby +@dogs = Dog.paginate(page: params[:page], :per_page => 5) +``` + +app/views/_dogs.html.erb +```ruby +<%= will_paginate @dogs, renderer: BootstrapPagination::Rails %> +``` +## Add the ability to for a user to input multiple dog images on an edit form or new dog form + +app/views/_form.html.erb +```ruby +<%= f.input :images, as: :file, :input_html => { :multiple => true } %> +``` + +app/controllers/dogs_controller.rb +```ruby + def dog_params + params.require(:dog).permit(:name, :description, images: []) + end +``` + +## Associate dogs with owners + +app/models/dog.rb +```ruby + belongs_to :owner, optional: true, + primary_key: :id, + foreign_key: :owner_id, + class_name: 'User' +``` + +## Allow editing only by owner +app/controllers/dogs_controller.rb +```ruby + before_action :require_login, only: [:new, :create] +``` + +app/controllers/application_controller.rb +```ruby +def require_login + redirect_to dogs_url unless current_user + end +``` +app/views/show.html.erb +```ruby +<% if current_user && current_user.id == @dog.owner_id %> + <%= link_to "Edit #{@dog.name}'s Profile", edit_dog_path %> + <%= link_to "Delete #{@dog.name}'s Profile", dog_path, method: :delete, data: { confirm: 'Are you sure?' } %> + <% end %> +``` + +## Allow users to like other dogs (not their own) + +app/controller/likes_controller.rb +```ruby +class LikesController < ApplicationController + before_action :require_login + + def create + @like = Like.new(like_params) + @like.liker_id = current_user.id + @like.dog_id = params[:dog_id] + + respond_to do |format| + if @like.save + @dog = Dog.find(params[:dog_id]) + + format.html { redirect_to @dog } + format.json { render :show, status: :created, location: @dog } + + else + format.json { render json: @like.errors.full_messages, status: 422 } + end + end + + end + + def destroy + @like = Like.find(params[:id]) + @dog = Dog.find(@like.dog_id) + @like.destroy + + respond_to do |format| + format.html { redirect_to @dog } + end + end + + private + def like_params + params.permit(:dog_id, :liker_id) + end +end +``` + +app/views/show.html.erb +```ruby + <% if current_user && @dog.owner_id != current_user.id %> + <% if @like %> + <%= link_to "Unlike", like_url(@like.id), method: :delete %> + <% else %> + <%= link_to "Like", dog_likes_url(@dog), method: :post %> + <% end %> + <% end %> +``` + +## Allow sorting the index page by number of likes in the last hour +app/controllers/dogs_controller.rb +```ruby + def index + if params[:sort_params] + subquery = Like.select(:id, :dog_id, :user_id).where(created_at: (Time.now - 1.hour)..Time.now) + @dogs = Dog.paginate(page: params[:page], :per_page => 5) + .joins("LEFT JOIN (#{subquery.to_sql}) AS likes ON dogs.id = likes.dog_id") + .group(:id) + .order("count(likes.id) desc") + else + @dogs = Dog.paginate(page: params[:page], :per_page => 5) + end + end +``` + + +## Display the ad.jpg image after every 2 dogs in the index page + +```ruby +<% if dog_counter % 2 == 1 %> +
+
+

Collar for Sale!

+ <%= image_tag image_url('ad.jpg'), class: "ad-photo", alt: "Photo of ad" %> +
+
+<% end %> +``` + +# Frontend + +## Display profile images in a functioning carousel (for the dog detail page that has more than one profile image) + +app/views/show.html.erb +```ruby +

<%= @dog.name %>

+<% if @dog.images.length > 1 %> +
+ +
+<% else %> + <% @dog.images.each do |image| %> + <%= image_tag url_for(image), class: "item-image mx-auto d-block", alt: "Photo of #{@dog.name}" %> + <% end %> +<% end %> + +
+

<%= @dog.description %>

+

Likes: <%= @dog.likes.count %>

+ +
+ <% if current_user && @dog.owner_id != current_user.id %> + <% if @like %> + <%= link_to "Unlike", like_url(@like.id), method: :delete %> + <% else %> + <%= link_to "Like", dog_likes_url(@dog), method: :post %> + <% end %> + <% end %> + + <% if current_user && current_user.id == @dog.owner_id %> + <%= link_to "Edit #{@dog.name}'s Profile", edit_dog_path %> + <%= link_to "Delete #{@dog.name}'s Profile", dog_path, method: :delete, data: { confirm: 'Are you sure?' } %> + <% end %> +
+
+``` + +## Use flexbox, CSS grids, or a grid framework to display the homepage's dog profile thumbnails in a responsive grid layout + +```ruby +
+
+ <%= link_to "Sort By Likes", :controller => "dogs", :action => "index", :sort_params => true %> +
+
+ <%= render partial: 'thumbnail', collection: @dogs, as: :dog %> +
+ +
+``` + +## Use utility classes within a layout framework (Bootstrap, Foundation, Material Design, or another) to add a structured layout to the page without custom CSS. + +The use of utility classes with Bootstrap can be seen throughout the application. + +## Refactor the homepage from its current state as a server-rendered page to a client-rendered page, where you request data from `/dogs.json` and display data from the response. + +app/view/index.html.erb +Adds clicking functionality that triggers an ajax request when page number is clicked. +```html + +``` + +app/views/index.js.erb +Created an index.js.erb file to replace the contents in dogs with paged table data such that clicking on a page triggers an ajax request. +```javascript +$("#dogs").html('<%= escape_javascript(render 'dogs') %>'); +$('.pagination a').attr('data-remote', 'true'); +``` \ No newline at end of file diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index cf84c56e..147d8ac9 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -27,13 +27,13 @@ header { } .item { - height: 300px; + height: 450px; } -.item > img { +.item-image, .item > img { object-fit: cover; - width: 300px; - height: 300px; + width: 450px; + height: 450px; margin: 0 auto; } diff --git a/app/views/dogs/_dogs.html.erb b/app/views/dogs/_dogs.html.erb index 6f6a9830..c518e5c3 100644 --- a/app/views/dogs/_dogs.html.erb +++ b/app/views/dogs/_dogs.html.erb @@ -5,9 +5,8 @@
<%= render partial: 'thumbnail', collection: @dogs, as: :dog %>
- - +
diff --git a/app/views/dogs/show.html.erb b/app/views/dogs/show.html.erb index 7ac3d62a..3c869ded 100644 --- a/app/views/dogs/show.html.erb +++ b/app/views/dogs/show.html.erb @@ -1,7 +1,6 @@ -
-

<%= @dog.name %>

-
- +

<%= @dog.name %>

+<% if @dog.images.length > 1 %> +
+
+<% else %> + <% @dog.images.each do |image| %> + <%= image_tag url_for(image), class: "item-image mx-auto d-block", alt: "Photo of #{@dog.name}" %> + <% end %> +<% end %> -

<%= @dog.description %>

+
+

<%= @dog.description %>

Likes: <%= @dog.likes.count %>

@@ -47,4 +53,4 @@ <%= link_to "Delete #{@dog.name}'s Profile", dog_path, method: :delete, data: { confirm: 'Are you sure?' } %> <% end %>
-
+
\ No newline at end of file From 262fa17adf660efddaa2156e9bd1a5e72525cd9a Mon Sep 17 00:00:00 2001 From: Maggie Date: Tue, 19 Mar 2019 22:28:41 -0400 Subject: [PATCH 24/26] Update ReadMe --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a7374832..687302a1 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,7 @@ app/views/show.html.erb ## Use flexbox, CSS grids, or a grid framework to display the homepage's dog profile thumbnails in a responsive grid layout +app/views/_dogs.html.erb ```ruby
@@ -246,8 +247,9 @@ The use of utility classes with Bootstrap can be seen throughout the application ## Refactor the homepage from its current state as a server-rendered page to a client-rendered page, where you request data from `/dogs.json` and display data from the response. -app/view/index.html.erb -Adds clicking functionality that triggers an ajax request when page number is clicked. +Adds clicking functionality that triggers an ajax request when page number is clicked.
+
+app/view/index.html.erb ```html ``` - -app/views/index.js.erb -Created an index.js.erb file to replace the contents in dogs with paged table data such that clicking on a page triggers an ajax request. +Created an index.js.erb file to replace the contents in dogs with paged table data such that clicking on a page triggers an ajax request.
+
+app/views/index.js.erb ```javascript $("#dogs").html('<%= escape_javascript(render 'dogs') %>'); $('.pagination a').attr('data-remote', 'true'); From 84157f07788bd02ce911f8032f28d704bf0f1e86 Mon Sep 17 00:00:00 2001 From: Maggie Date: Tue, 19 Mar 2019 23:16:20 -0400 Subject: [PATCH 25/26] Update ReadMe --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 687302a1..070a4990 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ app/view/index.html.erb }); ``` -Created an index.js.erb file to replace the contents in dogs with paged table data such that clicking on a page triggers an ajax request.
+Created a javascript view to replace the contents in dogs with paged table data such that clicking on a page triggers an ajax request.

app/views/index.js.erb ```javascript From 22f14dea589fad943f4cf79b6d8b6bba4439bb9e Mon Sep 17 00:00:00 2001 From: Maggie Date: Wed, 20 Mar 2019 00:55:49 -0400 Subject: [PATCH 26/26] Update ReadMe --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 070a4990..60003e36 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,7 @@ app/controllers/dogs_controller.rb ## Display the ad.jpg image after every 2 dogs in the index page +app/views/_thumbnail.html.erb ```ruby <% if dog_counter % 2 == 1 %>
@@ -247,8 +248,6 @@ The use of utility classes with Bootstrap can be seen throughout the application ## Refactor the homepage from its current state as a server-rendered page to a client-rendered page, where you request data from `/dogs.json` and display data from the response. -Adds clicking functionality that triggers an ajax request when page number is clicked.
-
app/view/index.html.erb ```html ``` -Created a javascript view to replace the contents in dogs with paged table data such that clicking on a page triggers an ajax request.
+Created a javascript view to to be executed when the ajax request is returned. The following code replaces the contents of the dogs div with the dogs partial.

app/views/index.js.erb ```javascript