Skip to content

Commit

Permalink
submission_confirmation: return item with json
Browse files Browse the repository at this point in the history
If JSON is requested when submitting an item, the JSON representation
of the requested item will be returned upon successful submission.
  • Loading branch information
mistydemeo committed Aug 20, 2012
1 parent 51c2571 commit b4e276b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

item.save

submission_confirmation
submission_confirmation item
end

get "/lost/addfound" do
Expand All @@ -79,7 +79,7 @@

item.save

submission_confirmation
submission_confirmation item
end

not_found do
Expand Down
5 changes: 4 additions & 1 deletion helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ def search_response_for results
end
end

def submission_confirmation
def submission_confirmation item
status 200

if not json_requested?
content_type :text
"Thanks for submitting your #{params["item"]}!"
else
content_type :json
item.to_hash.to_json
end
end

Expand Down

0 comments on commit b4e276b

Please sign in to comment.