From 3ea39ca725e28f83fbea4a6ebaa037697cb8dde9 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 23 Jan 2015 20:53:19 -0500 Subject: Add actions to NotesController * Create routes for notes actions * Add actions to NotesController allowing us to interact with it through a JSON API --- app/controllers/notes_controller.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index c94d2e3..7b9e4eb 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -1,2 +1,34 @@ class NotesController < ApplicationController + protect_from_forgery with: :null_session + + def index + render :json => Note.all.order(:created_at => :desc) + end + + def show + render :json => Note.find(params[:id]) + end + + def create + note = Note.create(note_params) + render :json => note + end + + def update + note = Note.find(params[:id]) + note.update(note_params) + render :json => note + end + + def destroy + note = Note.find(params[:id]) + note.destroy + render :json => note + end + + private + + def note_params + params.require(:note).permit(:title, :body) + end end -- cgit v1.2.3