Will_paginate wont_paginate for me!

Sorry for the cheesy topic name couldn’t resist.

B4 I go into details I’m rocking Rails 1.2.6. I’m hosting on MediaTemple
and they seem to working on some issue between their grid servers and
2.0.

I’m struggling with pagination. I spent a few hours discovering that
everyone thinks you should use a plugin to do your paginations. It seems
will_paginate is popular so I settled on that. It seems to have
installed just fine - all the files are there and there was no errors.
However, when I insert the code it doesn’t seem to like it.

I’m new to rails so I’m sure I’ve just overlooked something simple - if
someone can help I’d be very grateful.

in my controller I have the following code

class ThumbController < ApplicationController

model :thumb

def list
@thumbs = Thumb.paginate :page => params[:page], :per_page => 15
end

end

In my list view I have the following (btw this works fine with my simple
@thumbs = Thumb.find(:all)” I had in my old controller.)

  <% for thumb in @thumbs %><a href="<%= thumb.url %>"><img

src="/images/thumbs/<%= thumb.filename %>" target="_blank" alt=" "
border=“0” /><% end %>

<%= will_paginate @thumbs %>

As I say, I’ve probably just missed something dumb, but no matter how
many tutorials or examples I go through I can’t seem to figure what it
is :frowning:

Thanks in advance to some kind soul :slight_smile:

Did you look at:

This helps alot as the main will_paginate site doesn’t seem to work.

Jon

On Dec 23, 2007 9:01 AM, Bill G. [email protected]

Hi Jon

Yeah, I checked this out.

It helped me set it up tho - the special conditions this guy uses threw
me a little. I was hoping what I’m trying to set up is simpler.

Once I get it to work this cast will really help me to move the code
into the model.

Cheers

ps - cool name, is that a typo?

Jon G. wrote:

Did you look at:
#51 will_paginate - RailsCasts

This helps alot as the main will_paginate site doesn’t seem to work.

Jon

On Dec 23, 2007 9:01 AM, Bill G. [email protected]

Do you have more than 15 thumbnail images?
If not, just set the :per_page down to 1 or 2 and see it begins to
work.
If you have no images don’t expect much;-)

fredistic

When trying to figure out what could be your problem with
will_paginate I come to conclusion that something is fishy with your
Thumb model.
If Thumb.find(:all) is working than the only reason that will_paginate
won’t perform should be that limit-offset query that is used is
returning empty record set.
You should look development log file for SQL statements that are
performed and you will find the way to the solution.

If you can be more specific than, perhaps, we can help you even more.

On Dec 23, 8:59 pm, Bill G. [email protected]

haha yeah, i wish it was that simple - there’s about 25 images in there.

as I said when I display all without the Will_paginate they display
fine.

i’m wondering if will_paginate is note working on the server - does
anyone know a simple way for me to test? Though, even more likely is I
screwed up in my code :wink:

fredistic wrote:

Do you have more than 15 thumbnail images?
If not, just set the :per_page down to 1 or 2 and see it begins to
work.
If you have no images don’t expect much;-)

fredistic

Dejan D. wrote:

When trying to figure out what could be your problem with
will_paginate I come to conclusion that something is fishy with your
Thumb model.

Here is the content of thumb.rb

class Thumb < ActiveRecord::Base
end

As you can see I added nothing here - could this be the issue?

If Thumb.find(:all) is working than the only reason that will_paginate
won’t perform should be that limit-offset query that is used is
returning empty record set.
You should look development log file for SQL statements that are
performed and you will find the way to the solution.

Great idea to check out the logs - below seems to be the errors
generated when I try and access the page with the will_paginate
included.

Thanks a lot for your input.

Processing ApplicationController#list (for 85.27.49.251 at 2007-12-29
06:43:55) [GET]
Session ID: 145bc5e03a9492916fa16a2edcc15faf
Parameters: {“action”=>“list”, “controller”=>“thumb”}

LoadError (Expected
/home/15922/containers/rails/gggallery/app/controllers/thumb_controller.rb
to define ThumbController):
/home/15922/data/rubygems/gems/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:249:in
load_missing_constant' /home/15922/data/rubygems/gems/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:452:inconst_missing’
/home/15922/data/rubygems/gems/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:464:in
const_missing' /home/15922/data/rubygems/gems/gems/activesupport-1.4.4/lib/active_support/inflector.rb:250:inconstantize’
/home/15922/data/rubygems/gems/gems/activesupport-1.4.4/lib/active_support/core_ext/string/inflections.rb:148:in
constantize' /home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/routing.rb:1317:inrecognize’
/home/15922/data/rubygems/gems/gems/rails-1.2.6/lib/dispatcher.rb:40:in
dispatch' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/../lib/mongrel/rails.rb:76:inprocess’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/…/lib/mongrel/rails.rb:74:in
synchronize' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/../lib/mongrel/rails.rb:74:inprocess’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/…/lib/mongrel.rb:155:in
process_client' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/../lib/mongrel.rb:154:ineach’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/…/lib/mongrel.rb:154:in
process_client' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/../lib/mongrel.rb:281:inrun’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/…/lib/mongrel.rb:281:in
initialize' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/../lib/mongrel.rb:281:innew’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/…/lib/mongrel.rb:281:in
run' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/../lib/mongrel.rb:264:ininitialize’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/…/lib/mongrel.rb:264:in
new' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/../lib/mongrel.rb:264:inrun’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/…/lib/mongrel/configurator.rb:282:in
run' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/../lib/mongrel/configurator.rb:281:ineach’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/…/lib/mongrel/configurator.rb:281:in
run' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/mongrel_rails:128:inrun’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/…/lib/mongrel/command.rb:212:in
`run’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/mongrel_rails:281

Hi

I rebuilt the page the way it was - ie without will_paginate. It worked
fine as before and generated no errors in the log. Then I reverted to
include will_paginate. Now I get an error different to the log above. I
also restarted my application.


Processing ThumbController#list (for 85.27.49.251 at 2007-12-29
07:11:20) [GET]
Session ID: 145bc5e03a9492916fa16a2edcc15faf
Parameters: {“action”=>“list”, “controller”=>“thumb”}
Rendering within layouts/application
Rendering thumb/list

ActionView::TemplateError (undefined method page_count' for #<Array:0xb75e3bcc>) on line #22 of app/views/thumb/list.rhtml: 19: <div id="rightNav"></div> 20: 21: </div> 22: <%= will_paginate @thumbs %> /home/15922/containers/rails/gggallery/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb:45:inwill_paginate’
/home/15922/containers/rails/gggallery/app/views/thumb/list.rhtml:22:in
_run_rhtml_47app47views47thumb47list46rhtml' /home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_view/base.rb:325:insend’
/home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_view/base.rb:325:in
compile_and_render_template' /home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_view/base.rb:301:inrender_template’
/home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_view/base.rb:260:in
render_file' /home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/base.rb:812:inrender_file’
/home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/base.rb:717:in
render_with_no_layout' /home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/layout.rb:247:inrender_without_benchmark’
/home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:50:in
render' /usr/lib/ruby/1.8/benchmark.rb:293:inmeasure’
/home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:50:in
render' /home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/base.rb:1102:inperform_action_without_filters’
/home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/filters.rb:696:in
call_filters' /home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/filters.rb:688:inperform_action_without_benchmark’
/home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:66:in
perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:inmeasure’
/home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:66:in
perform_action_without_rescue' /home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/rescue.rb:83:inperform_action’
/home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/base.rb:435:in
send' /home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/base.rb:435:inprocess_without_filters’
/home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/filters.rb:684:in
process_without_session_management_support' /home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/session_management.rb:114:inprocess’
/home/15922/data/rubygems/gems/gems/actionpack-1.13.6/lib/action_controller/base.rb:334:in
process' /home/15922/data/rubygems/gems/gems/rails-1.2.6/lib/dispatcher.rb:41:indispatch’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel/rails.rb:76:in
process' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel/rails.rb:74:insynchronize’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel/rails.rb:74:in
process' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel.rb:155:inprocess_client’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel.rb:154:in
each' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel.rb:154:inprocess_client’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel.rb:281:in
run' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel.rb:281:ininitialize’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel.rb:281:in
new' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel.rb:281:inrun’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel.rb:264:in
initialize' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel.rb:264:innew’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel.rb:264:in
run' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel/configurator.rb:282:inrun’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel/configurator.rb:281:in
each' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel/configurator.rb:281:inrun’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/mongrel_rails:128:in
run' /home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/lib/mongrel/command.rb:212:inrun’
/home/15922/data/rubygems/gems/gems/mongrel-1.1.1-i386-linux/bin/mongrel_rails:281

Yay, I fixed it :slight_smile:

Dejan was right, there was something fishy in my model - ie nothing!

Thanks to this post - I Will Paginate — err.the_blog

I found that I needed the following code in my thumb.rb.

cattr_reader :per_page
@@per_page = 15

Thanks for the pointer.