2014-01-13 41 views
0

我正在尝试用Kaminari宝石分页多个表。我试着在我的应用程序控制器,产生一个数组做到这一点,像这样:与Kaminari宝石发生故障

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

我然后采取@paginate,在我的泛音一个使用它比呈现桌,就像这样:

<%= paginate @paginate %> 

,但我不断收到:

NoMethodError in Admin::ApplicationController#index 
undefined method `page' for ["errors", "messages", "subscribers"]:Array 

这里是我已经得到了代码:

Application_Controller.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 

_table.html.erb

<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

<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> 

如果你有什么事,让我知道,我把它。

谢谢!

回答

0

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

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) 
+0

非常感谢我给它一个尝试:-) –

+0

让我知道它是怎么回事......如果有帮助,不要忘记接受答案。 :) –

+0

仍然不怕工作。我有同样的错误接受这一次它不是'未定义的方法页'它现在'未定义的方法分页' –