diff options
| author | Teddy Wing | 2015-01-23 20:53:19 -0500 | 
|---|---|---|
| committer | Teddy Wing | 2015-01-23 20:53:19 -0500 | 
| commit | 3ea39ca725e28f83fbea4a6ebaa037697cb8dde9 (patch) | |
| tree | 2776273da20b726e008556816c40a00f1d1e28c8 /app | |
| parent | 1d8d8322f0595dcf13f65e13c6ad4ec4bb2e410f (diff) | |
| download | Notes-angular-demo-3ea39ca725e28f83fbea4a6ebaa037697cb8dde9.tar.bz2 | |
Add actions to NotesController
* Create routes for notes actions
* Add actions to NotesController allowing us to interact with it
  through a JSON API
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/notes_controller.rb | 32 | 
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 | 
