Newbie : assign a value to a variable...

K

Kroeger, Simon (ext)

=20
-----Original Message-----
From: Jan Svitok [mailto:[email protected]]=20
Sent: Monday, August 28, 2006 4:01 PM
To: ruby-talk ML
Subject: Re: Newbie : assign a value to a variable...
=20
Thanks for the trick.

But the next problem is that if params[:per_page] equals 0=20 then per_page
equals 0 and I get the error message "must have at least=20 one item per
page" from the Rails paginate option...
=20
per_page =3D @params[:per_page] || 20 # default
per_page =3D 20 if per_page <=3D 0 # validity check
=20
or the other way round:
=20
per_page =3D @params[:per_page] # assignment
per_page =3D nil if per_page <=3D 0 # validity check
per_page ||=3D 20 # default
=20
Choose what you like best.

or get them all at once:

per_page =3D @params.fetch:)per_page, 0).nonzero? || 20

cheers

Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top