首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kaminari Gem有问题

Kaminari Gem有问题
EN

Stack Overflow用户
提问于 2014-01-13 18:03:43
回答 1查看 425关注 0票数 0

我试着用Kaminari Gem分页多张桌子。我试图通过在我的应用程序控制器中生成一个数组来做到这一点,如下所示:

代码语言:javascript
复制
@paginate = %w(errors messages subscribers).page(params[:page]).per(15)

然后,我使用了@paginate,并在我的一个部分中使用它来呈现表,如下所示:

代码语言:javascript
复制
<%= paginate @paginate %>

但我一直收到一个:

代码语言:javascript
复制
NoMethodError in Admin::ApplicationController#index
undefined method `page' for ["errors", "messages", "subscribers"]:Array

下面是我得到的密码:

Application_Controller.rb

代码语言:javascript
复制
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

结束

_table.html.erb

代码语言:javascript
复制
<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>

_row.html.erb

代码语言:javascript
复制
<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>

如果你还需要什么,告诉我,我会把它放上去的。

谢谢你!!

EN

回答 1

Stack Overflow用户

发布于 2014-01-13 18:54:11

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

代码语言:javascript
复制
paginate(:page => params[:page], :per_page => 15)

所以在你的例子中

代码语言:javascript
复制
@paginate = %w(errors messages subscribers).page(params[:page]).per(15)

你真正想要的是:

代码语言:javascript
复制
@paginate = %w(errors messages subscribers).paginate(:page => params[:page], :per_page => 15)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21098224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档