Skip to content

Commit

Permalink
pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferwills committed Jun 2, 2020
1 parent 31d2a11 commit 2c25343
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 17 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ gem 'jquery-rails', '~> 4.4.0'
gem 'image_processing', '~> 1.11.0'
gem 'active_storage-send_zip', '~> 0.3.3'
gem 'active_storage_validations', '~> 0.8.9'
gem 'kaminari', '~> 1.2.1'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
Expand Down
13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
kaminari (1.2.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1)
kaminari-activerecord (= 1.2.1)
kaminari-core (= 1.2.1)
kaminari-actionview (1.2.1)
actionview
kaminari-core (= 1.2.1)
kaminari-activerecord (1.2.1)
activerecord
kaminari-core (= 1.2.1)
kaminari-core (1.2.1)
listen (3.2.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -225,6 +237,7 @@ DEPENDENCIES
image_processing (~> 1.11.0)
jbuilder (~> 2.7)
jquery-rails (~> 4.4.0)
kaminari (~> 1.2.1)
listen (~> 3.2)
pg
puma (~> 4.1)
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class ImagesController < ApplicationController
# GET /images
# GET /images.json
def index
@images = Image.all
@images = Image.all.page params[:page]

end

# GET /images/1
Expand Down Expand Up @@ -43,7 +44,7 @@ def create

end
if errors.empty?
redirect_to root_path, notice: 'Image was successfully created.'
redirect_to action: :index, notice: 'Image was successfully created.', uploaded_success: true
end
end

Expand Down
12 changes: 0 additions & 12 deletions app/controllers/site_controller.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/site_helper.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/models/image.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Image < ApplicationRecord
has_one_attached :file

validates :file, attached: true, content_type: ['image/png', 'image/jpg', 'image/jpeg'], size: { less_than: 10.megabytes , message: 'is too big' }

paginates_per 10

end
7 changes: 7 additions & 0 deletions app/views/images/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

<% if params[:uploaded_success] %>
<div class="alert alert-success" role="alert">
Files Uploaded Successfully!
</div>
<% end %>
<%= paginate @images %>

<div class="card-columns">
<% @images.each do |img| %>
<div class="card">
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Rails.application.routes.draw do

# get 'site/upload'
get 'images/upload'
post 'images/create'
delete 'images/destroy_all'
Expand Down

0 comments on commit 2c25343

Please sign in to comment.