berk / tr8n

This repository has moved to:
https://github.com/tr8n/tr8n
MIT License
280 stars 37 forks source link

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

Open jmccartie opened 11 years ago

jmccartie commented 11 years ago

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 commented 10 years ago

@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