Mailinglist Archive: yast-devel (163 mails)

< Previous Next >
Re: [yast-devel] WebYaST: how to pass empty string to rest-service?
  • From: Martin Vidner <mvidner@xxxxxxx>
  • Date: Wed, 16 Sep 2009 10:18:56 +0200
  • Message-id: <20090916081856.GA6248@xxxxxxxxxxxxxxxxxx>
On Wed, Sep 16, 2009 at 09:47:46AM +0200, Jiří Suchomel wrote:
Hi,
in administrator module I have a POST request from client that contains the
information about root password and mail aliases. Sometimes I would like to
pass an empty value (for mail aliases, to reset it to no alias) and to
distinguish the empty value from nil (nil has a meaning do not try to save
this, while empty means save empty).

Rails will not let you :-(
at least for hash values.

Hash#from_xml has
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/hash/conversions.rb:
# blank or nil parsed values are represented by nil
elsif value.blank? || value['nil'] == 'true'
nil
...

"An object is blank if it‘s false, empty, or a
whitespace string. For example, "", " ", nil, [], and {} are blank."
http://api.rubyonrails.org/classes/Object.html#M000279

BTW, Hash#from_xml also looks if an array has a single element and
unwraps it. Helpful, huh?

If you cannot adapt your API to deal with this, I suggest writing
(finding?) a stricter from_xml.
--
Martin Vidner, YaST developer
http://en.opensuse.org/User:Mvidner

Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
References