Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method 'per' for ActiveRecord::Relation #61

Open
jmccartie opened this issue Jun 10, 2013 · 1 comment
Open

undefined method 'per' for ActiveRecord::Relation #61

jmccartie opened this issue Jun 10, 2013 · 1 comment

Comments

@jmccartie
Copy link

Getting the following error trying to access "/

NoMethodError at /phrases (line 45)
undefined method `per' for #<ActiveRecord::Relation:0x007fa717aaa4b8>

method_missing(gem) activerecord-3.2.13/lib/active_record/relation/delegation.rb

   40         to_a.send(method, *args, &block)
   41       elsif arel.respond_to?(method)
   42         ::ActiveRecord::Delegation.delegate method, :to => :arel
   43         arel.send(method, *args, &block)
   44       else
   45         super
   46       end
   47     end
   48   end
   49 end

I've followed the Rails 3.2.2 setup instructions. "/tr8n/dashboard" works fine, but "/phrases" and a few other tabs throw this same error.

Any ideas?

@sjaveed
Copy link

sjaveed commented Oct 24, 2013

@jmccartie I suspect you have will_paginate installed which is conflicting with the kaminari pagination gem that tr8n and will_filter seem to require. Here's a workaround that has will_paginate behave like kaminari:

Create config/initializers/kaminari.rb which contains:

require 'kaminari'

# Have will_paginate emulate Kaminari for the gems that have kaminari as a dependency
Kaminari.configure do |config|
  config.page_method_name = :per_page_kaminari

  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
end

Add the following to the top of the app/helpers/application_helper.rb file:

def paginate model
  will_paginate(model)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants