Hi,

I'm trying to find a descent solution for the following problem:

Lets say I have a model called List. When you create a list, a name is
required (validation is in place).
But when a user creates a list in the application, a simular object
needs to be created on a remote system through the use of an API.

First idea would be to add your validation (presence) on name create a
after_validation callback. So after the validation the object would be
created on the remote system.

The problem however is, when the remote object creation fails (no
connection, udated remote api with an extra restriction, ...) I want to
notify the user of this and don't let the local object be created.

My first thought was adding some error handling in the callback method
and when that fails, throwing the error into the object errors hash.
The thing I overlooked was that "save" clears out the errors hash and
reruns the valid? method, that in turn runs the validations again but
doesn't look at the result of callbacks.

So how do you solve such an issue in a clean way?

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 5, '12 at 2:28p
activeMar 5, '12 at 2:28p
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Michael Rigart: 1 post

People

Translate

site design / logo © 2021 Grokbase