wip: Kaminari pagination
This commit is contained in:
4
Gemfile
4
Gemfile
@@ -73,8 +73,6 @@ end
|
|||||||
gem "devise", "~> 4.9"
|
gem "devise", "~> 4.9"
|
||||||
|
|
||||||
# Pagination gem
|
# Pagination gem
|
||||||
# gem "kaminari"
|
gem "kaminari", "~> 1.2"
|
||||||
|
|
||||||
# gem "net-pop", "~> 0.1.2"
|
# gem "net-pop", "~> 0.1.2"
|
||||||
|
|
||||||
gem "kaminari", "~> 1.2"
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
class PartiesController < ApplicationController
|
class PartiesController < ApplicationController
|
||||||
# Display all events
|
# Display all events
|
||||||
def index
|
def index
|
||||||
@parties = Party.includes(:user).upcoming.page(params[:page]).per(12)
|
@parties = Party.includes(:user).upcoming.page(params[:page]).per(1)
|
||||||
|
# @parties = Party.page(params[:page]).per(12)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Display desired event
|
# Display desired event
|
||||||
|
|||||||
25
app/views/kaminari/twitter_bootstrap/_paginator.html.erb
Normal file
25
app/views/kaminari/twitter_bootstrap/_paginator.html.erb
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<nav aria-label="Page navigation">
|
||||||
|
<ul class="pagination">
|
||||||
|
<% if paginator.prev_page %>
|
||||||
|
<li class="page-item">
|
||||||
|
<%= link_to 'Previous', url_for(page: paginator.prev_page), class: 'page-link' %>
|
||||||
|
</li>
|
||||||
|
<% else %>
|
||||||
|
<li class="page-item disabled"><span class="page-link">Previous</span></li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% paginator.page_range.each do |page| %>
|
||||||
|
<li class="page-item <%= 'active' if page == paginator.current_page %>">
|
||||||
|
<%= link_to page, url_for(page: page), class: 'page-link' %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if paginator.next_page %>
|
||||||
|
<li class="page-item">
|
||||||
|
<%= link_to 'Next', url_for(page: paginator.next_page), class: 'page-link' %>
|
||||||
|
</li>
|
||||||
|
<% else %>
|
||||||
|
<li class="page-item disabled"><span class="page-link">Next</span></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
@@ -39,7 +39,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-8">
|
<div class="mt-8">
|
||||||
<%= paginate @parties, theme: 'twitter_bootstrap' %>
|
<%# paginate @parties, theme: 'twitter_bootstrap' %>
|
||||||
|
<%= paginate @parties %>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="text-center py-12">
|
<div class="text-center py-12">
|
||||||
|
|||||||
@@ -94,6 +94,26 @@ class PartyTest < ActiveSupport::TestCase
|
|||||||
assert_not party.save
|
assert_not party.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should save valid party" do
|
||||||
|
user = User.create!(
|
||||||
|
email: "test@example.com",
|
||||||
|
password: "password123",
|
||||||
|
password_confirmation: "password123"
|
||||||
|
)
|
||||||
|
|
||||||
|
party = Party.new(
|
||||||
|
name: "Valid Party Name",
|
||||||
|
slug: "valid-party-name",
|
||||||
|
description: "Valid description for the party that is long enough",
|
||||||
|
latitude: 48.8566,
|
||||||
|
longitude: 2.3522,
|
||||||
|
venue_name: "Test Venue",
|
||||||
|
venue_address: "123 Test Street",
|
||||||
|
user: user,
|
||||||
|
)
|
||||||
|
assert party.save
|
||||||
|
end
|
||||||
|
|
||||||
# Test enum states
|
# Test enum states
|
||||||
test "should have valid states" do
|
test "should have valid states" do
|
||||||
assert_equal %w[draft published canceled sold_out], Party.states.keys
|
assert_equal %w[draft published canceled sold_out], Party.states.keys
|
||||||
@@ -128,7 +148,7 @@ class PartyTest < ActiveSupport::TestCase
|
|||||||
assert_equal :ticket_types, association.options[:through]
|
assert_equal :ticket_types, association.options[:through]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Test scopes - using class methods directly to avoid DB connection issues
|
# Test scopes
|
||||||
test "should respond to featured scope" do
|
test "should respond to featured scope" do
|
||||||
assert_respond_to Party, :featured
|
assert_respond_to Party, :featured
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user