This is really a newbie question...
Here is the simple code...
per_page = 20
per_page = @params[:per_page]
You got very bright answers from very good people, or was it the other way
The answers were of type
var = val || default_val
As it seems that you are accessing a Hash object, you could do the following
which is semantically different and this is the main reason I anwser your
per_page = @params.fetch( :per_page, 20 )
Now where is the difference:
if @params does not contain the key :per_page, 20 is returned, however if
@params[:per_page] was set to nil or false, nil or false is returned
It is up to you to know what you need
Hope that helps
Is there a better way to do this (put the parameter in the variable if
On 8/28/06, Nicolas Blanco <email@example.com> wrote:
the parameter is not null, otherwise put 20) ?
Posted via http://www.ruby-forum.com/.
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.
- Albert Einstein