aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/notes_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/notes_controller.rb')
-rw-r--r--app/controllers/notes_controller.rb32
1 files changed, 32 insertions, 0 deletions
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