diff options
author | Teddy Wing | 2015-01-23 20:54:48 -0500 |
---|---|---|
committer | Teddy Wing | 2015-01-23 20:54:48 -0500 |
commit | 4432d0b7d1d2ee43258c6147f0881af923d07312 (patch) | |
tree | 2776273da20b726e008556816c40a00f1d1e28c8 /app/controllers/notes_controller.rb | |
parent | d7d88ccd11cda59619fea44e14997ed21b5f9a4e (diff) | |
parent | 3ea39ca725e28f83fbea4a6ebaa037697cb8dde9 (diff) | |
download | Notes-angular-demo-4432d0b7d1d2ee43258c6147f0881af923d07312.tar.bz2 |
Merge branch 'create-api-endpoints'
Diffstat (limited to 'app/controllers/notes_controller.rb')
-rw-r--r-- | app/controllers/notes_controller.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb new file mode 100644 index 0000000..7b9e4eb --- /dev/null +++ b/app/controllers/notes_controller.rb @@ -0,0 +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 |