From: "Kroeger, Simon (ext)" Date: 2006-08-29T00:14:01+09:00 Subject: Re: Newbie : assign a value to a variable... > -----Original Message----- > From: Jan Svitok [mailto:jan.svitok@gmail.com] > Sent: Monday, August 28, 2006 4:01 PM > To: ruby-talk ML > Subject: Re: Newbie : assign a value to a variable... > > On 8/28/06, Nicolas Blanco 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. or get them all at once: per_page = @params.fetch(:per_page, 0).nonzero? || 20 cheers Simon