I'm trying to paginate multiple tables with the Kaminari Gem. I've tried to do this by generating an array in my application controller, like so:
@paginate = %w(errors messages subscribers).page(params[:page]).per(15)
I've then taken @paginate
and used it in one of my partials than renders the tables, like so:
<%= paginate @paginate %>
But I keep receiving a:
NoMethodError in Admin::ApplicationController#index
undefined method `page' for ["errors", "messages", "subscribers"]:Array
Here is the code that I've got:
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
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>
If you need anything else, let me know and I'll put it up.
Thank you!!