views for kaminari

This commit is contained in:
Adrian Hinz 2019-05-15 18:53:47 +02:00
parent b2ce16fb69
commit a3741d18a2
7 changed files with 21 additions and 4 deletions

View File

@ -14,7 +14,7 @@ module Admin
# GET /admin/courses/1
# GET /admin/courses/1.json
def show
@weeks = @course.weeks
@weeks = @course.weeks.page(params[:page])
end
# GET /admin/courses/new

View File

@ -27,7 +27,7 @@ module Admin
# POST /admin/weeks.json
def create
@week = Week.new(admin_week_params)
@course = Course.find(@week.course_id)
@course = @week.course# .find(@week.course_id)
params[:course_id] = @course.id
respond_to do |format|
if @week.save
@ -75,10 +75,11 @@ module Admin
def set_object
@week = Week.find(params[:id])
@course = @week.course
params[:course_id] = @course.id
end
def collection
@weeks = Week.by_course(params[:course_id])
@weeks = Week.by_course(params[:course_id]).page(paramas[:page])
end
# Never trust parameters from the scary internet, only allow the white list through.

View File

@ -38,6 +38,19 @@ module ViewsHelper
end
end
def paginator(object)
paginate(object, remote: true, theme: 'twitter-bootstrap-4',
pagination_class: 'justify-content-center',
nav_class: 'pg-right', params: normalize_pagination_params)
end
def normalize_pagination_params
params.to_unsafe_h.inject({}) do |params_hash, p|
params_hash[p[0]] = nil unless p[0] == 'controller' || p[0] == 'search'
params_hash
end
end
=begin
<div class="dropdown no-arrow">
<a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">

View File

@ -22,5 +22,5 @@
<% end %>
</tbody>
</table>
<%= paginate @courses, remote: true, theme: 'twitter-bootstrap-4', pagination_class: 'justify-content-center' %>
<%= paginator @courses %>
<% end %>

View File

@ -0,0 +1 @@
$('#ajax_list').html("<%= escape_javascript(render('/admin/weeks/partials/weeks')) %>");

View File

@ -0,0 +1 @@
$('#ajax_list').html("<%= escape_javascript(render('/admin/weeks/partials/weeks')) %>");

View File

@ -22,4 +22,5 @@
<% end %>
</tbody>
</table>
<%= paginator @weeks, params: { controller: 'admin/weeks', action: :index } %>
<% end %>