OK, here's a quick summary on how to use will_paginate

install the gem:
  gem install will_paginate

edit the the file config/environment.rb in your application's
directory.  add this line at the bottom:
  require 'will_paginate'

now, in your controller:

def search
  # I prefer setting my options hash separately, it makes it more readable
  # take note of the :conditions key.  the way you currently do it is
vulnerable to
  # SQL injection because you stick the params directly in the SQL string.
  # this method of using a Hash gets rid of the risk as Rails will escape
the params
  options = { :order =>'author ASC',
                     :conditions => [ "keywords like :search_value", {
:search_value => "%#{params[:searchtextfield]} %" } ],
                     :page => params[:page]
                   }
  @nejmvalues = NEJM.paginate(options)
end

to have a link to the pages in your view, you just put:
  <%= will_paginate @nejmvalues %>

by default, will_paginate will display 50 entries per page if i remember
right.
to customize this, you can create a class variable in your model.  so in
your
NEJM model, add these two lines at the start of the class declaration:

  cattr_reader :per_page
  @@per_page = 10   # will_paginate will display 10 results per page

hope this helps.

/franz

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to