Question

I am a bit new to rails, and one of my task is migrating a rails 2.1 app to 3.2. Start steb by step, first 2.1 to 2.3 rails, and now to 3.2.

Can't use bundle or gem file but I have all the gems I need installed.

My issue is now converting will paginate methods.

I had my requires in an /config/initializer/load.rb in this order

require 'rails' require 'rails/all' require 'prototype-rails' require 'will_paginate'

The libs are loaded with success.

But when I try to use paginate in my source I get this error.

NoMethodError (undefined method `page' for #<Broadcast:0x00000003fd9320>):
  app/controllers/broadcasts_controller.rb

my controller is has this code:

@broadcasts = Broadcast.page(params[:page] || 1).select(select_clause).order( order_clause)

the broadcast model is something like

class Broadcast < ActiveRecord::Base
  extend PhoneNumberFormatValidation
  ...
end

I try to put the "require will_paginate" just before my controller but it didn't work. If I run rails console

[user1@virtual-rh6x64 web]$ rails c
irb(main):001:0> require 'will_paginate'
=> false

I don't understand why can't find will paginate methods. Does he work with ActiveRecord::Base?

my gems are:

*** LOCAL GEMS ***

actionmailer (3.2.11)
actionpack (3.2.11)
activemodel (3.2.11)
activerecord (3.2.11)
activerecord-oracle_enhanced-adapter (1.4.1)
activeresource (3.2.11)
activesupport (3.2.11)
arel (3.0.2)
bigdecimal (1.1.0)
builder (3.0.4)
bundler (1.2.3)
coderay (1.0.5)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.4.0)
dbi (0.4.5)
deprecated (2.0.1)
erubis (2.7.0)
execjs (1.3.2)
fastercsv (1.5.0)
hike (1.2.1)
i18n (0.6.1)
io-console (0.3)
journey (1.0.4)
jquery-rails (2.1.4)
json (1.7.7)
libv8 (3.11.8.13 x86_64-linux)
libxml-ruby (2.1.0)
mail (2.4.4)
method_source (0.8.2)
mime-types (1.19)
minitest (3.2.0)
multi_json (1.7.2)
pg (0.14.1)
polyglot (0.3.3)
prototype-rails (3.2.1)
pry (0.9.12)
puma (1.6.3)
rack (1.4.1)
rack-cache (1.2)
rack-ssl (1.3.2)
rack-test (0.6.2)
rails (3.2.11)
railties (3.2.11)
rake (0.9.2.2)
rdoc (3.12)
ref (1.0.2)
ruby-oci8 (2.1.2)
ruby-plsql (0.5.0)
sass (3.2.5)
sass-rails (3.2.5)
slop (3.4.6)
sprockets (2.2.1)
therubyracer (0.11.4)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.12)
tzinfo (0.3.35)
uglifier (1.3.0)
will_paginate (3.0.2)
Was it helpful?

Solution

Try using

 require 'will_paginate/active_record'

To load specific childs you may need to track down what childs will_paginate loads in a normal setup through Bundler.. because in that way it doesn't require loading these childs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top