From c636f067db0f6918872193c8feee86b6ed5dc417 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 23 Jan 2015 19:45:41 -0500 Subject: Generate Note model --- app/models/note.rb | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 app/models/note.rb (limited to 'app') diff --git a/app/models/note.rb b/app/models/note.rb new file mode 100644 index 0000000..1b03bd6 --- /dev/null +++ b/app/models/note.rb @@ -0,0 +1,2 @@ +class Note < ActiveRecord::Base +end -- cgit v1.2.3 From 1d8d8322f0595dcf13f65e13c6ad4ec4bb2e410f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 23 Jan 2015 19:47:16 -0500 Subject: Generate NotesController --- app/assets/javascripts/notes.coffee | 3 +++ app/assets/stylesheets/notes.scss | 3 +++ app/controllers/notes_controller.rb | 2 ++ app/helpers/notes_helper.rb | 2 ++ 4 files changed, 10 insertions(+) create mode 100644 app/assets/javascripts/notes.coffee create mode 100644 app/assets/stylesheets/notes.scss create mode 100644 app/controllers/notes_controller.rb create mode 100644 app/helpers/notes_helper.rb (limited to 'app') diff --git a/app/assets/javascripts/notes.coffee b/app/assets/javascripts/notes.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/notes.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/notes.scss b/app/assets/stylesheets/notes.scss new file mode 100644 index 0000000..56d31f5 --- /dev/null +++ b/app/assets/stylesheets/notes.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the notes controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb new file mode 100644 index 0000000..c94d2e3 --- /dev/null +++ b/app/controllers/notes_controller.rb @@ -0,0 +1,2 @@ +class NotesController < ApplicationController +end diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb new file mode 100644 index 0000000..8078f73 --- /dev/null +++ b/app/helpers/notes_helper.rb @@ -0,0 +1,2 @@ +module NotesHelper +end -- cgit v1.2.3 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') 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