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
# GET /admin/courses/1.json # GET /admin/courses/1.json
def show def show
@weeks = @course.weeks @weeks = @course.weeks.page(params[:page])
end end
# GET /admin/courses/new # GET /admin/courses/new

View File

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

View File

@ -38,6 +38,19 @@ module ViewsHelper
end end
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 =begin
<div class="dropdown no-arrow"> <div class="dropdown no-arrow">
<a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <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 %> <% end %>
</tbody> </tbody>
</table> </table>
<%= paginate @courses, remote: true, theme: 'twitter-bootstrap-4', pagination_class: 'justify-content-center' %> <%= paginator @courses %>
<% end %> <% 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 %> <% end %>
</tbody> </tbody>
</table> </table>
<%= paginator @weeks, params: { controller: 'admin/weeks', action: :index } %>
<% end %> <% end %>