Mailinglist Archive: yast-devel (59 mails)

< Previous Next >
Re: [yast-devel] Webyast - models in webclient and webservice - summary
  • From: Ladislav Slezak <lslezak@xxxxxxx>
  • Date: Tue, 16 Mar 2010 11:09:29 +0100
  • Message-id: <4B9F58D9.2050506@xxxxxxx>
Dne 9.3.2010 08:38, Josef Reidinger napsal(a):
My idea was, that you should use save! in backend. It reports error on
and on frontend you can parse errors and create user friendly message for
user. Of
course we could have some predefined helper, which takes common validation
and translate it to default error message (not yet done, but it is easy to

OK, I have implemented it. It is in

Example usage:

1) Add validations into your REST backend model, example from the repositories

# URL cannot be empty
validates_presence_of :url
# priority must be in range 0-200
validates_inclusion_of :priority, :in => 0..200

2) Use! in the REST controller (it returns 422 error code when
validation fails)

3) In the client controller:

# display success
flash[:message] = _("Repository '#{}' has been updated.")
if @repo.errors.size > 0
# display errors from the response
flash[:error] = generate_error_messages @repo, attribute_mapping
# response doesn't contain details, show a generic error message
flash[:error] = _("Cannot update repository '#{}': Unknown

Where attribute_mapping is a map
:id => _('Alias'),
:enabled => _('Enabled'),

It simply maps the attribute names to printable/translatable strings
(they should be same as the names which were displayed in the form).

The page will then contain error "URL can't be blank" if the passed
URL is empty.


Best Regards

Ladislav Slez√°k
Yast Developer
SUSE LINUX, s.r.o. e-mail: lslezak@xxxxxxx
Lihovarsk√° 1060/12 tel: +420 284 028 960
190 00 Prague 9 fax: +420 284 028 951
Czech Republic
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >