module Croods::Controller::AlreadyTaken

Protected Instance Methods

already_taken(exception) click to toggle source
# File lib/croods/controller/already_taken.rb, line 14
def already_taken(exception)
  match = exception.message.match(/\((.+)\)=\(.+\) already exists/)
  attribute = match && model.human_attribute_name(match[1])

  message = attribute ? "#{attribute} already taken" : 'Already taken'

  render status: :unprocessable_entity, json: {
    id: 'already_taken',
    message: message
  }
end