我正在使用 cancancan 进行授权。并且正在使用 will_paginate 进行表分页。它工作正常,直到我在控制器中添加 load_and_authorize_resource 。在控制器中使用 load_and_authorize_resource 时,will_paginate 会抛出ActionView::Template::Error (undefined method
total_pages' for #)`: Abilyty.rb:
def initialize(user)
if user.user_type == "ADMIN" then
can :manage, :all
cannot :manage, ParentMessageController
elsif user.user_type == "MANAGEMENT" then
can :manage, :all
cannot :manage, ParentAttendance
end
控制器:
class AssignmentsController < ApplicationController
before_action :set_assignment, only: [:show, :edit, :update, :destroy]
load_and_authorize_resource
def index
getAssignments
end
def getAssignments
@assignments = Assignment.all
if (@assignments != nil && @assignments.length > 0) then
@assignments = @assignments.paginate(:per_page => 5, :page => params[:page])
end
end
看法:
<% if @assignments != nil then%>
<%= will_paginate @assignments, :class => @paginationClass.to_s, renderer: BootstrapPagination::Rails %>
<%end%>