Ruby on Rails Monday, November 24, 2014

hello, i develop  rest api for my project and using grape

And i have two questions:

1. For every error i want to have some specific code. Like twillio. where should I store these codes?
2.
How should I organize the work with the codes and grape?

For example:

I have user model

class User < ActiveRecord::Base
  validates :phone, presence: true   # code 1001
  validated :phone,
uniqueness: true  # code 1002
  validates :first_name, presence: true # code 1003
  validates :last_name, presence: true #code 1004
end

In grape api i have something like this

post do
        authenticated!
         user = User.new(params)
        if user.save
          { id: user.id }
        else
          error!({ errors: user.errors }, 422)
        end
      end



I thought to use the function fail and using Grape rescue_from generate response
but I'm not sure that this is true


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/cdc63658-f10f-4e9f-95d6-61d9fe5554c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment