SpineJS handle server-side rails model validations -
i have model, let's phone call book
. in rails, when book saved, validate uniqueness of it's isbn number. front end end, have simple spinejs app let's me add together new book.
in spinejs:
class app.book extends spine.model @configure 'book', 'name', 'isbn' @extend spine.model.ajax validate: -> "name required" unless @name "isbn required" unless @isbn
and in rails:
class book < activerecord::base attr_accessible :name, :isbn validates :name, :presence => true validates :isbn. :presence => true, :uniqueness => true end
my issue in spinejs app, happily saves new book duplicate isbn number, though rails server returns validation errors.
is there way handle error client-side on save?
spine's manual claims:
if validation fail server-side, it's error in client-side validation logic rather user input.
i don't see how work uniqueness requirement. may workable if can load database info impact validation client side and can somehow avoid multi-user race conditions.
you can grab "ajaxerror" event , tell user retry, although catching "ajaxerror" goes against recommendations in manual. iirc may have juggling object ids convince spine new record in fact not created.
additionally, can fire pre-emptive validation requests user editing data, user's convenience. in theory can still nail race status else creates conflicting record before user hits save.
personally switched backbone since found spine's careless mental attitude error handling scary.
ruby-on-rails ruby-on-rails-3 javascriptmvc spine.js
No comments:
Post a Comment