On 8/28/06, Nicolas Blanco <slainer68 / gmail.com> wrote:
> Thanks for the trick.
>
> But the next problem is that if params[:per_page] equals 0 then per_page
> equals 0 and I get the error message "must have at least one item per
> page" from the Rails paginate option...

per_page = @params[:per_page] || 20 # default
per_page = 20 if per_page <= 0  # validity check

or the other way round:

per_page = @params[:per_page] # assignment
per_page = nil if per_page <= 0  # validity check
per_page ||= 20 # default

Choose what you like best.

> unknown wrote:
> > Hi --
> >
> > On Mon, 28 Aug 2006, Nicolas Blanco wrote:
> >
> >> end
> >>
> >> Is there a better way to do this (put the parameter in the variable if
> >> the parameter is not null, otherwise put 20) ?
> >
> > You can use the || (or) operator:
> >
> >
> >
> > David
>
>
> --
> Posted via http://www.ruby-forum.com/.
>
>