0

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
Matt
  • 8,367
  • 4
  • 31
  • 61
HUSTEN
  • 5,117
  • 4
  • 24
  • 38

2 Answers2

2

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?

EDIT:

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}"
Community
  • 1
  • 1
MrYoshiji
  • 54,334
  • 13
  • 124
  • 117
  • I'm using the gem called Kaminari. It does everything. here's source code. https://github.com/amatsuda/kaminari/blob/master/lib/kaminari/helpers/action_view_extension.rb Please take a look at line 88 – HUSTEN Jan 25 '13 at 14:56
  • @HUSTEN I updated my answer, hope this helps! If not, please post what you've set in your yml translation file – MrYoshiji Jan 25 '13 at 15:14
  • Now another error came out:( undefined method `model_name' for # – HUSTEN Jan 25 '13 at 15:26
2

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
sjain
  • 23,126
  • 28
  • 107
  • 185
  • I'm not using will_paginate at all. – HUSTEN Jan 25 '13 at 14:57
  • I was using version 0.13.0 until an hour ago, it didn't have this error then. But previous version had the error with another locale problem. So I updated it to 0.14.1 but this new error came out. – HUSTEN Jan 25 '13 at 15:00
  • @users = User.scoped.page(params[:page]).order("created_at DESC") – HUSTEN Jan 25 '13 at 15:21
  • Try , `<%= page_entries_info(@communities, :entry_name => 'model_name').html_safe %>` where model_name is your model's name. – sjain Jan 25 '13 at 15:43