Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# README
<!-- NHO: missing README -->

This README would normally document whatever steps are necessary to get the
application up and running.
Expand Down
1 change: 0 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class ApplicationController < ActionController::Base
# protect_from_forgery with: :exception
protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
end
20 changes: 16 additions & 4 deletions app/controllers/places_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
class PlacesController < ApplicationController
def index
@places = Place.all
respond_to do |format|
format.json { render json: @places }
end
# NHO: since you will not be serving HTML with this app, you can remove the respond_to block
# and only render json, i.e:

# respond_to do |format|
# format.json { render json: @places }
# end
render json: @places
end

def show
# NHO: shouldn't this be .findy_by so it will return an object and not an array?
@place = Place.where(zip: params[:id])
respond_to do |format|
format.json { render json: @place }
Expand All @@ -16,18 +21,25 @@ def show
def create
@place = Place.new(place_params)
respond_to do |format|
# NHO: nice validation checking, the only thing I might be conscious of
# is to rendering the same type of data from the controller
# ie. if it saves, we get back an object, but if it doesnt, we get back an array
# this will lead to more logic on the front end
if @place.save!
format.json { render json: @place }
else
# NHO: could render the last error message so you get back just an object
format.json { render json: @place.errors }
end
end
end

# NHO: missing update

def destroy
@place = Place.find_by(zip: params[:id])
@place.destroy
render json: {"status": "deleted"}
render json: {status: "deleted"}
end

private
Expand Down
1 change: 1 addition & 0 deletions app/models/place.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class Place < ApplicationRecord
# NHO: this code looks a little out of place...
# skip_before_action :verify_authenticity_token
end