[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: newby question on validation

ES

6/3/2005 9:30:00 PM


Le 3/6/2005, "Matteo Corti" <corti@inf.ethz.ch> a écrit:
>On 2005-06-03, gregarican <greg.kujawa@gmail.com> wrote:
>> You should be able to access this text field's value by referring to
>> @param. For example, here's a text input field that would appear in an
>> HTML form:
>>
>><INPUT TYPE="TEXT" SIZE="5" MAXLENGTH="5"
>> NAME="thisControl[thisNumber]">
>>
>> You could access the value of this text field using the following in
>> your accompanying controller.rb file:
>>
>> retrievedValue = @params['thisControl']['thisNumber']
>> render_text "The text field's value as entered is #{retrievedValue}..."
>>
>> You could validate the value using conditional statements of the common
>> variety:
>>
>> render_text "The value is too large" if retrievedValue.to_i > 100
>>
>> Does this make sense?
>
>Yes I was trying something like that:
>
> if @params['a']['b'] != nil and @params['a']['b'].to_i < 100
> # do something
>
>but I have problems when the field is left empty (i.e. empty string). The
>param is not null and it seems to pass even the second test since an empty
>string is converted to 0. Any suggestion on how I could check if there is a
>valid integer?

Does this work?

p = @params['a']['b']
if p and not p.empty? and p.to_i < 100

>Many thanks for the help.
>
>Matteo

E

--
template<typename duck>
void quack(duck& d) { d.quack(); }