Skip to content

Instantly share code, notes, and snippets.

@sranso
Created March 11, 2014 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sranso/9477788 to your computer and use it in GitHub Desktop.
Save sranso/9477788 to your computer and use it in GitHub Desktop.
# app.rb
# create new quote + author
post '/quotes' do
begin
params.merge! JSON.parse(request.env["rack.input"].read)
rescue JSON::ParserError
logger.error "Cannot parse request body."
end
@author = Author.find_or_create_by(params[:author])
@author.quotes.build(:body => params[:body])
@author.save!
redirect '/'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment