我试着用Kaminari Gem分页多张桌子。我试图通过在我的应用程序控制器中生成一个数组来做到这一点,如下所示:
@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"> </th>
<% if model.name == "Error" %><th> </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>
如果你还需要什么,告诉我,我会把它放上去的。
谢谢你!!
发布于 2014-01-13 18:54:11
你没有正确地设置“页面”。应该是这样的:
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)https://stackoverflow.com/questions/21098224
复制相似问题