addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramlinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [NYC-rb] Handling Rails validations with Spine Models.

From: Jake H.
Sent on: Friday, September 14, 2012 1:02 AM
Hey Stephen,

While not specifically spine related, we us ActiveModel::Serializers and have an ErrorSerializer class.


-Jake

On Thursday, September 13, 2012 at 10:03 PM, Stephen Schor wrote:

Greetings.

After a more-than-cursory search online - I'm swallowing my pride and come to you, hat in hand with a question.

Is there an established pattern for handing sever-side Validation errors in spine so the errors are reflected in your spine model? I'm not talking about spine's validate model that subclasses of Spine.Model have - more like errors like validates_presence_of.

The spinejs site suggests:

def create
  @page = Page.new(params[:page])
  if @page.save
    respond_with(@page, status: :created, location: @page)
  else
    respond_with(@page.errors, status: :unprocessable_entity) 
  end
end


Example

The ActiveRecord model Book validates_presence_of :name.
If your Rails app's BooksController#create action contains.

if @book.save
  respond_with @book
else
  respond_with(@book, status: :unprocessable_entity)
end

and you pop into a JS Console and run:

my_book = App.Book.create({}) //no name, will vail validation

my_book doesn't have the errors serialized on it - and that makes
sense because @book.to_json doesn't serialize @book's errors collection.

So - what's up - is there an established pattern for this?

If you help me I will get you a few beers...out of Pivotal's fridge.
You're welcome - no big.
-Stephen




--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Stephen Schor ([address removed]) from NYC.rb.
To learn more about Stephen Schor, visit his/her member profile
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]

Our Sponsors

  • Pivotal Labs

    Provides the awesome event space we use every month!

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy