Ruby on rails 与卡米纳里宝石有麻烦

Ruby on rails 与卡米纳里宝石有麻烦,ruby-on-rails,arrays,pagination,gem,kaminari,Ruby On Rails,Arrays,Pagination,Gem,Kaminari,我正在尝试使用Kaminari Gem对多个表进行分页。我试图通过在我的应用程序控制器中生成一个数组来实现这一点,如下所示: @paginate = %w(errors messages subscribers).page(params[:page]).per(15) <%= paginate @paginate %> 然后,我使用了@paginate并将其用于我的一个部分,然后呈现表格,如下所示: @paginate = %w(errors messages subscribe

我正在尝试使用Kaminari Gem对多个表进行分页。我试图通过在我的应用程序控制器中生成一个数组来实现这一点,如下所示:

@paginate = %w(errors messages subscribers).page(params[:page]).per(15)
<%= paginate @paginate %>
然后,我使用了
@paginate
并将其用于我的一个部分,然后呈现表格,如下所示:

@paginate = %w(errors messages subscribers).page(params[:page]).per(15)
<%= paginate @paginate %>
以下是我得到的代码:

应用程序\u控制器.rb

class Admin::ApplicationController < InheritedResources::Base
protect_from_forgery
include ResourcesHelper
layout "admin"

#Setup
before_filter :set_resource_variable
before_filter :set_pagination_variable, only: :index

#Authentication
skip_before_filter :authenticate_user!
before_filter :authenticate_admin!

#Authorization
skip_before_filter :check_authentication

#Index
#Custom Index For Application/Index (no inheritance) 
def index
    @users = User.all
    @attributes = %w(messages subscribers)
    @paginate = %w(errors messages subscribers).page(params[:page]).per(15)
end

#Create
def create
    create! { collection_path }
end

#Update
def update
    update! { collection_path }
end


private
#Set Model Variable
def set_resource_variable
    @resource = self.resource_class
    @model = "#{@resource}".downcase.to_sym
end 

#Pagination
def set_pagination_variable
    #params[:page] ||= "1"
end

#Strong Params
def permitted_params
    attributes = attributes(@resource) + %w(user_id admin_id) + [image_pages_attributes: [:caption, image_attributes: [:image]]]
    params.permit(@model => attributes)
end
<h2><%= model %></h2> 
<% unless collection.blank? %>
<table class="sort">
    <thead>
        <tr>
            <% model.attribute_names.each do |attr| %>
                <th><%= model.human_attribute_name(attr) %></th>
            <% end %>
            <th colspan="2">&nbsp;</th>
            <% if model.name == "Error" %><th>&nbsp;</th><% end %>
        </tr>
    </thead>
    <tbody>
        <%= render partial: "admin/resources/table/row", collection: collection, as: :resource, locals: {model: model}  %>
    </tbody>
</table>
<tr data-link="<%= polymorphic_path([:admin, resource]) %>">
<% model.attribute_names.each do |attr| %>
    <td><%= resource.send(attr) %></td>
<% end %>
<% if model.name == "Error" %>
    <td><%= link_to "Read", admin_error_read_path(resource.id), method: :put, remote: :true, class: "read" %></td>
<% end %>
<td><%= link_to "Edit", edit_polymorphic_path([:admin, resource]) %></td>
<td><%= link_to "Delete", polymorphic_path([:admin, resource]), method: :delete, data: {confirm: "Are you sure?"} %></td>
class Admin::ApplicationControllerattributes)
终止
结束

\u table.html.erb

class Admin::ApplicationController < InheritedResources::Base
protect_from_forgery
include ResourcesHelper
layout "admin"

#Setup
before_filter :set_resource_variable
before_filter :set_pagination_variable, only: :index

#Authentication
skip_before_filter :authenticate_user!
before_filter :authenticate_admin!

#Authorization
skip_before_filter :check_authentication

#Index
#Custom Index For Application/Index (no inheritance) 
def index
    @users = User.all
    @attributes = %w(messages subscribers)
    @paginate = %w(errors messages subscribers).page(params[:page]).per(15)
end

#Create
def create
    create! { collection_path }
end

#Update
def update
    update! { collection_path }
end


private
#Set Model Variable
def set_resource_variable
    @resource = self.resource_class
    @model = "#{@resource}".downcase.to_sym
end 

#Pagination
def set_pagination_variable
    #params[:page] ||= "1"
end

#Strong Params
def permitted_params
    attributes = attributes(@resource) + %w(user_id admin_id) + [image_pages_attributes: [:caption, image_attributes: [:image]]]
    params.permit(@model => attributes)
end
<h2><%= model %></h2> 
<% unless collection.blank? %>
<table class="sort">
    <thead>
        <tr>
            <% model.attribute_names.each do |attr| %>
                <th><%= model.human_attribute_name(attr) %></th>
            <% end %>
            <th colspan="2">&nbsp;</th>
            <% if model.name == "Error" %><th>&nbsp;</th><% end %>
        </tr>
    </thead>
    <tbody>
        <%= render partial: "admin/resources/table/row", collection: collection, as: :resource, locals: {model: model}  %>
    </tbody>
</table>
<tr data-link="<%= polymorphic_path([:admin, resource]) %>">
<% model.attribute_names.each do |attr| %>
    <td><%= resource.send(attr) %></td>
<% end %>
<% if model.name == "Error" %>
    <td><%= link_to "Read", admin_error_read_path(resource.id), method: :put, remote: :true, class: "read" %></td>
<% end %>
<td><%= link_to "Edit", edit_polymorphic_path([:admin, resource]) %></td>
<td><%= link_to "Delete", polymorphic_path([:admin, resource]), method: :delete, data: {confirm: "Are you sure?"} %></td>

\u row.html.erb

class Admin::ApplicationController < InheritedResources::Base
protect_from_forgery
include ResourcesHelper
layout "admin"

#Setup
before_filter :set_resource_variable
before_filter :set_pagination_variable, only: :index

#Authentication
skip_before_filter :authenticate_user!
before_filter :authenticate_admin!

#Authorization
skip_before_filter :check_authentication

#Index
#Custom Index For Application/Index (no inheritance) 
def index
    @users = User.all
    @attributes = %w(messages subscribers)
    @paginate = %w(errors messages subscribers).page(params[:page]).per(15)
end

#Create
def create
    create! { collection_path }
end

#Update
def update
    update! { collection_path }
end


private
#Set Model Variable
def set_resource_variable
    @resource = self.resource_class
    @model = "#{@resource}".downcase.to_sym
end 

#Pagination
def set_pagination_variable
    #params[:page] ||= "1"
end

#Strong Params
def permitted_params
    attributes = attributes(@resource) + %w(user_id admin_id) + [image_pages_attributes: [:caption, image_attributes: [:image]]]
    params.permit(@model => attributes)
end
<h2><%= model %></h2> 
<% unless collection.blank? %>
<table class="sort">
    <thead>
        <tr>
            <% model.attribute_names.each do |attr| %>
                <th><%= model.human_attribute_name(attr) %></th>
            <% end %>
            <th colspan="2">&nbsp;</th>
            <% if model.name == "Error" %><th>&nbsp;</th><% end %>
        </tr>
    </thead>
    <tbody>
        <%= render partial: "admin/resources/table/row", collection: collection, as: :resource, locals: {model: model}  %>
    </tbody>
</table>
<tr data-link="<%= polymorphic_path([:admin, resource]) %>">
<% model.attribute_names.each do |attr| %>
    <td><%= resource.send(attr) %></td>
<% end %>
<% if model.name == "Error" %>
    <td><%= link_to "Read", admin_error_read_path(resource.id), method: :put, remote: :true, class: "read" %></td>
<% end %>
<td><%= link_to "Edit", edit_polymorphic_path([:admin, resource]) %></td>
<td><%= link_to "Delete", polymorphic_path([:admin, resource]), method: :delete, data: {confirm: "Are you sure?"} %></td>

如果你还需要什么,请告诉我,我会把它挂起来的

谢谢

您没有正确设置“页面”。应该是这样的:

paginate(:page => params[:page], :per_page => 15)
在你的例子中

@paginate = %w(errors messages subscribers).page(params[:page]).per(15)
你真正想要的是:

@paginate = %w(errors messages subscribers).paginate(:page => params[:page], :per_page => 15)

非常感谢,我会试试看:-)让我知道进展如何。。。如果答案有帮助,不要忘记接受它。:)恐怕还是不行。我有同样的错误接受这次它不是“未定义的方法页面”现在是“未定义的方法页面”嗯。。。你在运行什么版本的gem?什么版本的rails?当您进行
捆绑显示时,它会说什么?“kaminari”、“~>0.15.0”