will_paginate

Hello Guys I hope someone can help me I've been trying but without success to do a pagination using the will_paginate gem. When I'm listing all records the system paginates but when I'm doing a filter to show some records, just show the first five. Someone knows whats happening?

My code

CONTROLLER

  def index

    @contract = Contract.new(params[:contract])     page = (params[:page] ||= 1).to_i     @contracts = Contract.search_index({:page => page})     @legal_entities = LegalEntity.all(:select => "CD_PESSOA_JURIDICA, NM_PESSOA", :joins => [:person])

    @persons = Person.all

      respond_to do |format|         format.html # index.html.erb       end   end

  def list

    @contract = Contract.new(params[:contract])     page = (params[:page] ||= 1).to_i     @contracts = Contract.find_by_params(params[:contract])     @legal_entities = LegalEntity.all(:select => "CD_PESSOA_JURIDICA, NM_PESSOA", :joins => [:person])

    @person = Person.all     render :index

  end

VIEW <% form_for(@contract, :url => { :action => "list"}, :onKeyPress => "submit();" ) do |f| %> <!-- Início da Tabela de Filtro -->

<table class="Cabecalho" border="0">   <thead>     <tr>       <td colspan="4" class="titulos">Empresa:<br/>         <%= select(:contract, :CD_PESSOA_JURIDICA,                                @legal_entities.collect{ |p| [ p.NM_PESSOA, p.CD_PESSOA_JURIDICA]},                                 { :include_blank => true }) %>       </td>     </tr>     <tr>       <td width="30%" class="titulos">Número do contrato:<br/>         <%= f.text_field(:CD_CONTRATO, :style=>"width: 90%;", :maxlength=>"7", :onKeypress => "apenasnum(this);")%>       </td>       <td width="20%"class="titulos">Ano:<br/>         <%= f.text_field(:NO_ANO, :style=>"width: 90%;", :onKeypress => "apenasnum(this);")%>       </td>       <td width="40%"class="titulos">Objeto do contrato:<br/>         <%= f.text_field(:DS_OBJETO_CONTRATO, :style=>"width: 80%;", :onKeypress => "apenastex(this);")%>       </td>        <td width="9%" align="right" style="padding-right:35px;">         <%= image_submit_tag("lupa.png", :title => "Pesquisar")%>       </td>     </tr>   </thead> </table>

<br/>

<div class="tab_botao">   <%= link_to ( image_tag("incluir.jpg",:style=>"width: 16px; heigth:16px; border:0", :title =>"Incluir Novo"))+' Incluir Novo', new_contract_path %> </div>

<% if @contracts.empty? %> <div class="div_registro">     <p>Nemhum contrato foi encontrado</p> </div> <% else %>

<table cellpadding="0" cellspacing="1" class="Cabecalho">     <thead>       <tr class="Cabecalho_bg">         <th align="left" style="padding-left: 5px;">Numero Contrato</th>         <th align="left" style="padding-left: 5px;">Ano</th>         <th align="left" style="padding-left: 5px;">Empresa</th>         <th align="left" style="padding-left: 5px;">Objeto</th>         <th align="left" style="padding-left: 5px;">Termo Aditivo</th>       </tr>     </thead>

    <tbody class="zebra">        <% @contracts.each do |contract| %>           <tr>             <td style="padding-left:5px;"><%= link_to contract.CD_CONTRATO, contract %></td>             <td style="padding-left:5px;"><%= contract.NO_ANO %></td>             <td style="padding-left:5px;" ><%= contract.legal_entity.person.NM_PESSOA %></td>             <td style="padding-left:5px;"><%= contract.DS_OBJETO_CONTRATO %></td>             <td style="padding-left:5px;"><b><%= "#{contract.additiv_contracts.size} aditivos" %></b></td>           </tr>        <% end %>     </tbody>       <tr class="Cabecalho_bg">         <td colspan="6" class="Result">           Total de <b><%= @contracts.total_entries %></b> &iacute;tens.         </td>       </tr>

      <tr>         <td colspan="6" class="paginacao">           <%= will_paginate @contracts %>

        </td>       </tr> </table>   <% end %> <% end %>

Cheers

Raony Vieira ferreira wrote:

CONTROLLER

  def index     @contract = Contract.new(params[:contract])     page = (params[:page] ||= 1).to_i     @contracts = Contract.search_index({:page => page})     @legal_entities = LegalEntity.all(:select => "CD_PESSOA_JURIDICA, NM_PESSOA", :joins => [:person])     @persons = Person.all       respond_to do |format|         format.html # index.html.erb       end   end

  def list     @contract = Contract.new(params[:contract])     page = (params[:page] ||= 1).to_i     @contracts = Contract.find_by_params(params[:contract])     @legal_entities = LegalEntity.all(:select => "CD_PESSOA_JURIDICA, NM_PESSOA", :joins => [:person])     @person = Person.all     render :index   end

Seems like this should all be controller work (well, not quite, and this is based on the mislav-will_paginate gem)...

You could use a generic @contracts = Contract.paginate :conditions => cond, :page => params[:page]

where cond is your scoping criteria, such as:

cond = ['name LIKE ?', some_params_entry] or cond = ['1=1'] for the everything case

The only difference in your two methods is the Contract.find...

Not knowing what the search_index or find_by_params methods do precisely, could you create a single build_conditions method in the Contract model that returns 'cond' and covers all your search cases to simplify your logic?

index and list are awfully similar... do you need both?

The only difference in your two methods is the Contract.find...

Not knowing what the search_index or find_by_params methods do precisely, could you create a single build_conditions method in the Contract model that returns 'cond' and covers all your search cases to simplify your logic?

index and list are awfully similar... do you need both?

I don't need both, I tried but I had no success using generic I think I've done something wrong in model. Using generic i have to modify my model? I'm quite confused with that, because I usually use will_paginate without filter.

Cheers

Raony Vieira ferreira wrote:

I don't need both, I tried but I had no success using generic I think I've done something wrong in model.

Skinny controllers, fat models.

Given scoping criteria that may be coming in params, the model should know how to respond to those params for limiting return sets, and can adapt its 'cond' to account for those. Controller just knows to use the received cond in its paginate call.

Model:

class Contract   def build_conditions(params)     # the default returns     cond = ['1=1']     page = (params[:page] ||= 1).to_i     per_page = 15     if params[:partial_contract_name]       # return a scoping condition here, this can be as complex       # as you want/require       cond = ['name LIKE ?%', params[:partial_contract_name]     end     return cond, page, per_page   end end

Controller:

  def index     @contract = Contract.new(params[:contract])     cond, page, per_page = @contract.build_conditions(params)     @contracts = Contract.paginate :conditions => cond, :page => page, :per_page => per_page     @legal_entities = LegalEntity.all(:select => "CD_PESSOA_JURIDICA, NM_PESSOA", :joins => [:person])     @persons = Person.all     respond_to do |format|       format.html # index.html.erb     end   end

should be a nice generic implementation using will_paginate. Again, I don't know what was happening in your search_index or find_by_params methods.

I need help.

I input gem 'will_paginate' or config.gem 'will_paginate'

but got the undefined method `paginate' for #<Class:0x653996c>

Jeff Chen wrote:

I need help.

I input gem 'will_paginate' or config.gem 'will_paginate'

but got the undefined method `paginate' for #<Class:0x653996c>

On 8月26日, 下午11時01分, Raony Vieira ferreira <li...@ruby-forum.com>

The correct way is config.gem 'will_paginate' but if the will_paginate is already installed should have worked.

Thanks.

But I config.gem 'will_paginate' before the end of environment.rb and f the will_paginate is already installed but not worked. Got the undefined method `paginate' for #<Class:0x653996c> Why? May you give me a hint, or sample, let me fix it up.

config.gem must go inside the initializer.run block, not just before the end.

Post your environment.rb if you think you have it correctly, also the output of gem list --local and the full error that you are getting.

Colin

Dear Colin,

Thanks.

1. The environment.rb:

RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|   # Settings in config/environments/* take precedence over those specified here.   # Application configuration should go into files in config/ initializers   # -- all .rb files in that directory are automatically loaded.     config.gem 'will_paginate'   # Add additional load paths for your own custom dirs   # config.load_paths += %W( #{RAILS_ROOT}/extras )

  # Specify gems that this application depends on and have them installed with rake gems:install   # config.gem "bj"   # config.gem "hpricot", :version => '0.6', :source => "http:// code.whytheluckystiff.net"   # config.gem "sqlite3-ruby", :lib => "sqlite3"   # config.gem "aws-s3", :lib => "aws/s3"

  # Only load the plugins named here, in the order given (default is alphabetical).   # :all can be used as a placeholder for all plugins not explicitly named   # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

  # Skip frameworks you're not going to use. To use Rails without a database,   # you must remove the Active Record framework.   # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

  # Activate observers that should always be running   # config.active_record.observers = :cacher, :garbage_collector, :forum_observer

  # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.   # Run "rake -D time" for a list of tasks for finding time zone names.   config.time_zone = 'UTC'

  # The default locale is :en and all translations from config/locales/ *.rb,yml are auto loaded.   # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*. {rb,yml}')]   # config.i18n.default_locale = :de

end

2. The output of gem list --local: will_paginate <2.3.14>

3. The full error MSG: NoMethodError in ManageController#index

undefined method `paginate' for #<Class:0x679f940>

Please don't top post it makes it more difficult to follow the thread Thanks

... 1. The environment.rb:

RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config| # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/ initializers # -- all .rb files in that directory are automatically loaded. config.gem 'will_paginate' # Add additional load paths for your own custom dirs # config.load_paths += %W( #{RAILS_ROOT}/extras )

# Specify gems that this application depends on and have them installed with rake gems:install # config.gem "bj" # config.gem "hpricot", :version => '0.6', :source => "http:// code.whytheluckystiff.net" # config.gem "sqlite3-ruby", :lib => "sqlite3" # config.gem "aws-s3", :lib => "aws/s3"

# Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

# Skip frameworks you're not going to use. To use Rails without a database, # you must remove the Active Record framework. # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

# Activate observers that should always be running # config.active_record.observers = :cacher, :garbage_collector, :forum_observer

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. config.time_zone = 'UTC'

# The default locale is :en and all translations from config/locales/ *.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*. {rb,yml}')] # config.i18n.default_locale = :de

end

That looks OK. When you run script/server I presume you do not get an error about missing gems? Or any other error?

2. The output of gem list --local: will_paginate <2.3.14>

OK

3. The full error MSG: NoMethodError in ManageController#index

undefined method `paginate' for #<Class:0x679f940>

What is the path and filename of that controller? Can you post the code for the index method?

Colin

The manage_c0ntroller.rb:

class ManageController < ApplicationController

  def index     list     render :action => 'list'   end

  # GETs should be safe (see URIs, Addressability, and the use of HTTP GET and POST)   verify :method => :post, :only => [ :destroy, :create, :update ],          :redirect_to => { :action => :list }

  def list

    @items = Item.paginate(:page => params[:page], :per_page => 10)

  end     #@posts = Post.paginate :page => params[:page], :per_page => 50   def show     @item = Item.find(params[:id])   end

  def new     @item = Item.new   end

  def create     @item = Item.new(params[:item])     if @item.save       flash[:notice] = 'Item was successfully created.'       redirect_to :action => 'list'     else       render :action => 'new'     end   end

  def edit     @item = Item.find(params[:id])   end

  def update     @item = Item.find(params[:id])     if @item.update_attributes(params[:item])       flash[:notice] = 'Item was successfully updated.'       redirect_to :action => 'show', :id => @item     else       render :action => 'edit'     end   end

  def destroy     Item.find(params[:id]).destroy     redirect_to :action => 'list'   end end

The manage_c0ntroller.rb:

Did you note the first request in my previous email - not to top post? That means not to post your new message before the quotes of the previous message, but to insert your reply into the previous message. Now I have scroll up and down this email looking at what I asked and back up to see your response. It also makes it less likely that you will forget to answer a question.

In particular you have not confirmed that you do not get any errors when you start the server.

Also please can you confirm that if you remove the calls to paginate and just fetch all records that all works as expected.

Further comments below.

class ManageController < ApplicationController

def index list render :action => 'list' end

Again I am having to cut and paste from below, if you had not top posted I would not have had to do this. You previously said the error is

> NoMethodError in ManageController#index > undefined method `paginate' for #<Class:0x679f940>

I don't see any call to paginate so that is a bit odd. Please confirm exactly what is happening and make sure the code you post matches the error message. Post the full error trace for the message please.

And once again please don't top post.

Colin

> The manage_c0ntroller.rb:

Did you note the first request in my previous email - not to top post? That means not to post your new message before the quotes of the previous message, but to insert your reply into the previous message. Now I have scroll up and down this email looking at what I asked and back up to see your response. It also makes it less likely that you will forget to answer a question.

In particular you have not confirmed that you do not get any errors when you start the server.

Yes, confirm there is no any errors when start the server

Also please can you confirm that if you remove the calls to paginate and just fetch all records that all works as expected.

Yes, all works when remove call to paginate

Further comments below.

> class ManageController < ApplicationController

> def index > list > render :action => 'list' > end

Again I am having to cut and paste from below, if you had not top posted I would not have had to do this. You previously said the error is

>> > NoMethodError in ManageController#index >> > undefined method `paginate' for #<Class:0x679f940>

I don't see any call to paginate so that is a bit odd. Please confirm exactly what is happening and make sure the code you post matches the error message. Post the full error trace for the message please.

Here is the development.log: Processing ManageController#index (for 127.0.0.1 at 2010-08-30 17:30:14) [GET]   e[4;35;1mSQL (64.0ms)e[0m e[0mSHOW TABLESe[0m   e[4;36;1mItem Columns (403.0ms)e[0m e[0;1mSHOW FIELDS FROM `items`e[0m

NoMethodError (undefined method `paginate' for #<Class:0x675f980>):   app/controllers/manage_controller.rb:25:in `list'   app/controllers/manage_controller.rb:4:in `index'   c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'   c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'   c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'   c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'   c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'   c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'   c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'   c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'   c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'   c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'

Rendered rescues/_trace (144.0ms) Rendered rescues/_request_and_response (8.0ms) Rendering rescues/layout (internal_server_error)

And once again please don't top post.

Hope the post is correct this time. Thanks.

NoMethodError (undefined method `paginate' for #<Class:0x675f980>):   app/controllers/manage_controller.rb:25:in `list'   app/controllers/manage_controller.rb:4:in `index'   c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'   c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'   c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'   c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'   c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'   c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'   c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'   c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'   c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'   c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'

Rendered rescues/_trace (144.0ms) Rendered rescues/_request_and_response (8.0ms) Rendering rescues/layout (internal_server_error)

I don't know but try, check the will_paginate version and write in evironment.rb between the "Rails::Initializer.run do |config|" and the last end this

config.gem 'will_paginate', :version => 'your version'

and restart the server and check

... In particular you have not confirmed that you do not get any errors when you start the server.

Yes, I get not any errors when start the server.

Also please can you confirm that if you remove the calls to paginate and just fetch all records that all works as expected.

Yes, I did remove the calls to paginate, and just fetch all records that all works as expected.

... I don't see any call to paginate so that is a bit odd. Please confirm exactly what is happening and make sure the code you post matches the error message. Post the full error trace for the message please.

Processing ManageController#index (for 127.0.0.1 at 2010-08-30 17:30:14) [GET] [4;35;1mSQL (64.0ms) [0m [0mSHOW TABLES [0m [4;36;1mItem Columns (403.0ms) [0m [0;1mSHOW FIELDS FROM `items` [0m

NoMethodError (undefined method `paginate' for #<Class:0x675f980>): app/controllers/manage_controller.rb:25:in `list'

Right so the error is in list, that is why I asked for the whole error message.

app/controllers/manage_controller.rb:4:in `index' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each' c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'

I see that the error is from Item.paginate. You have not told us anything about the Item class. Can you show us the code for that class (delete methods that are not relevant before posting) and confirm the path and filename to that class.

I am running out of ideas however.

Colin

> NoMethodError (undefined method `paginate' for #<Class:0x675f980>): > app/controllers/manage_controller.rb:25:in `list' > app/controllers/manage_controller.rb:4:in `index' > c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' > c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' > c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' > c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start' > c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' > c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start' > c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each' > c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start' > c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start' > c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'

> Rendered rescues/_trace (144.0ms) > Rendered rescues/_request_and_response (8.0ms) > Rendering rescues/layout (internal_server_error)

I don't know but try, check the will_paginate version and write in evironment.rb between the "Rails::Initializer.run do |config|" and the last end this

config.gem 'will_paginate', :version => 'your version'

and restart the server and check

1. Checking the version: gem list -- local -> will_paginate <2.3.14>

2. and I add below code into environment:

   config.gem 'will_paginate', :version => '2.3.14'

3. Restart the server, and got the result: undefined method `paginate' for #<Class:0x66a2718>

>> ... >> In particular you have not confirmed that you do not get any errors >> when you start the server.

> Yes, I get not any errors when start the server.

>> Also please can you confirm that if you remove the calls to paginate >> and just fetch all records that all works as expected.

> Yes, I did remove the calls to paginate, and just fetch all records > that all works as expected.

>> ... >> I don't see any call to paginate so that is a bit odd. Please confirm >> exactly what is happening and make sure the code you post matches the >> error message. Post the full error trace for the message please.

> Processing ManageController#index (for 127.0.0.1 at 2010-08-30 > 17:30:14) [GET] > [4;35;1mSQL (64.0ms) [0m [0mSHOW TABLES [0m > [4;36;1mItem Columns (403.0ms) [0m [0;1mSHOW FIELDS FROM > `items` [0m

> NoMethodError (undefined method `paginate' for #<Class:0x675f980>): > app/controllers/manage_controller.rb:25:in `list'

Right so the error is in list, that is why I asked for the whole error message.

> app/controllers/manage_controller.rb:4:in `index' > c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' > c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' > c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' > c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start' > c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' > c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start' > c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each' > c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start' > c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start' > c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'

I see that the error is from Item.paginate. You have not told us anything about the Item class. Can you show us the code for that class (delete methods that are not relevant before posting) and confirm the path and filename to that class.

The item.rb of model is : class Item < ActiveRecord::Base end

Do I need to add the codes into the item.rb?

I am running out of ideas however.

I am so happy to get your support, because it confuse me for several months, and I believe you can help me because you own 6 stars in this Talk.

No, what you have looks ok.

Only one more suggestion I think, I seem to remember some-one having a similar problem and it went away when they used Mongrel instead of Webrick, though I do not understand why. I can only suggest you try that, so start the server with ruby script/server --mongrel and see what happens. I always use mongrel as for me it loads much faster.

Colin

>> >> ... >> >> In particular you have not confirmed that you do not get any errors >> >> when you start the server.

>> > Yes, I get not any errors when start the server.

>> >> Also please can you confirm that if you remove the calls to paginate >> >> and just fetch all records that all works as expected.

>> > Yes, I did remove the calls to paginate, and just fetch all records >> > that all works as expected.

>> >> ... >> >> I don't see any call to paginate so that is a bit odd. Please confirm >> >> exactly what is happening and make sure the code you post matches the >> >> error message. Post the full error trace for the message please.

>> > Processing ManageController#index (for 127.0.0.1 at 2010-08-30 >> > 17:30:14) [GET] >> > [4;35;1mSQL (64.0ms) [0m [0mSHOW TABLES [0m >> > [4;36;1mItem Columns (403.0ms) [0m [0;1mSHOW FIELDS FROM >> > `items` [0m

>> > NoMethodError (undefined method `paginate' for #<Class:0x675f980>): >> > app/controllers/manage_controller.rb:25:in `list'

>> Right so the error is in list, that is why I asked for the whole error message.

>> > app/controllers/manage_controller.rb:4:in `index' >> > c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' >> > c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' >> > c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' >> > c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start' >> > c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' >> > c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start' >> > c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each' >> > c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start' >> > c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start' >> > c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'

>> I see that the error is from Item.paginate. You have not told us >> anything about the Item class. Can you show us the code for that >> class (delete methods that are not relevant before posting) and >> confirm the path and filename to that class.

> The item.rb of model is : > class Item < ActiveRecord::Base > end

> Do I need to add the codes into the item.rb?

No, what you have looks ok.

Only one more suggestion I think, I seem to remember some-one having a similar problem and it went away when they used Mongrel instead of Webrick, though I do not understand why. I can only suggest you try that, so start the server with ruby script/server --mongrel

I did run: ruby script/server --mongrel , and got the result is "server : invalid option --mongrel". Where to get the mongrel, and how to fix it up when I run above command again?

I don't know, it just worked for me, in fact it defaults to mongrel on my Ubuntu install. Have you tried googling for rails install mongrel?

Colin