Hi --

On Mon, 28 Aug 2006, Nicolas Blanco wrote:

> Hi all!
>
> This is really a newbie question...
>
> Here is the simple code...
>
> if @params[:per_page].nil?
>      per_page = 20
>    else
>      per_page = @params[:per_page]
> 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:

   per_page = @params[:per_page] || 20


David

-- 
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
   ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com        => D[avid ]A[. ]B[lack's][ Web]log
http://www.manning.com/black     => book, Ruby for Rails
http://www.rubycentral.org       => Ruby Central, Inc.