Created
November 24, 2009 04:08
-
-
Save eedrummer/241623 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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