Skip to content

Instantly share code, notes, and snippets.

@eedrummer
Created November 24, 2009 04:08
Show Gist options
  • Save eedrummer/241623 to your computer and use it in GitHub Desktop.
Save eedrummer/241623 to your computer and use it in GitHub Desktop.
post '/' do
check_params
handle_extension if params[:type].eql?('extension')
handle_section if params[:type].eql?('section')
end
def check_params
unless ['extension', 'section'].include? params[:type]
halt 400,
"Your request must specify a type of section or extension"
end
end
def handle_extension
extension = Extension.new(
:type_id => params[:typeId],
:requirement => params[:requirement])
if extension.valid?
extension.save
status 201
else
if extension.errors.full_messages.include?(
"Extension with that type id already exists")
halt 409, "Extension with that type id already exists"
else
halt 400, extension.errors.full_messages.join(' ')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment