Reputation: 5197
Here's error and my codes. I'm using Kaminari
Error: undefined method `model_name' for #<Array:0x0000001d5abeb0>
73: <%= page_entries_info(@communities).html_safe %>
view
<%= page_entries_info(@communities).html_safe %>
Community controller
UPDATE* This is how I'm fetching now
@search = Community.search do
fulltext params[:search]
with(:location_id, params[:location]) if params[:location].to_i >0
with(:type_id, params[:type]) if params[:type].to_i >0
order_by :cached_votes_up, :desc
paginate :page => params[:page], :per_page => 10
end
@communities = @search.results
Upvotes: 0
Views: 1742
Reputation: 54902
You have a problem with your translation:
"%{total} total records. Displaying %{first} - %{last}"
Here it is expecting 3 arguments when you call this translation:
the variables total
, first
and last
but "you" give only these 2 variables: entry_name
& count
Can you provide more info about the page_entries_info
method please?
As you commented, https://github.com/amatsuda/kaminari/blob/master/lib/kaminari/helpers/action_view_extension.rb#L102 Line 102-109: You need to have in your .yml translation file(s) something like this:
en:
helpers:
page_entries_info:
one_page:
display_entries: "%{count} total records for %{entry_name}."
more_pages:
display_entries: "%{total} total records. Displaying %{first} - %{last}"
Upvotes: 2
Reputation: 23356
If you are using kaminari and will_paginate together, you will definitely face this error. In short, kaminari and will_paginate are incompatible to each other.
If you are using rails_admin
(which uses kaminari for pagination) and also using will_paginate
, you will need to add the following code to one of the initializers under config directory or you can create a new file, let say with name 'will_paginate' add the code, and place it into initializers directory.
if defined?(WillPaginate)
module WillPaginate
module ActiveRecord
module RelationMethods
def per(value = nil) per_page(value) end
def total_count() count end
end
end
module CollectionMethods
alias_method :num_pages, :total_pages
end
end
end
Upvotes: 2