How to calculate per_page value based on browser window size for will_paginate

def self.per_page

Any suggestion on how I can calculate this value base on the size of
the browser window?


Why not allow the user to choose this value (i.e. via a drop down
menu )?

If you go that route, don’t forget to store this preference somewhere
so your users don’t have to set it every time. (I’m looking at you


Ok, I tried as you suggested with:

<%= select_tag(:per_page, options_for_select(%w{10 20 30 40 50},
selected = session[:per_page]), :onchange => “session[:per_page] =
this.value”) %> Lines per page

I can’t seem to get the :onchange to set a new value for
session[:per_page]. I checked :onchange with an alert(this.value) and
it did what I expected.

Can you proved a sample of what I should be doing in :onchange


Thanks for your ideas.

I decided to make per_page an attribute of the user and set it at
login. That way it gives all my list pages a common look.

I had already put this inside a form_tag I am using for a search box,
so I didn’t want to add another form_tag. The search box and the
pagination boxes took up enough room on the page. Can you direct two
different form_tags to appear on the same line?

I still don’t get what I would put in the :onchange option. Can you
give me an example?

Can you proved a sample of what I should be doing in :onchange

I’ve used an “Apply” button inside of form_tag, which sends params
back to the controller and I set the session there.

If you wanted to use the :onchange event instead of requiring the user
to click on a button, you would probably have to send an
XMLHttpRequest to the server and then refresh the page with the new
paginated data.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs