aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2015-01-23 20:54:48 -0500
committerTeddy Wing2015-01-23 20:54:48 -0500
commit4432d0b7d1d2ee43258c6147f0881af923d07312 (patch)
tree2776273da20b726e008556816c40a00f1d1e28c8
parentd7d88ccd11cda59619fea44e14997ed21b5f9a4e (diff)
parent3ea39ca725e28f83fbea4a6ebaa037697cb8dde9 (diff)
downloadNotes-angular-demo-4432d0b7d1d2ee43258c6147f0881af923d07312.tar.bz2
Merge branch 'create-api-endpoints'
-rw-r--r--app/assets/javascripts/notes.coffee3
-rw-r--r--app/assets/stylesheets/notes.scss3
-rw-r--r--app/controllers/notes_controller.rb34
-rw-r--r--app/helpers/notes_helper.rb2
-rw-r--r--app/models/note.rb2
-rw-r--r--config/routes.rb55
-rw-r--r--db/migrate/20150124004310_create_notes.rb10
-rw-r--r--db/schema.rb23
-rw-r--r--test/controllers/notes_controller_test.rb7
-rw-r--r--test/fixtures/notes.yml9
-rw-r--r--test/models/note_test.rb7
11 files changed, 101 insertions, 54 deletions
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..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
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
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
diff --git a/config/routes.rb b/config/routes.rb
index 3f66539..c5c7483 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,56 +1,3 @@
Rails.application.routes.draw do
- # The priority is based upon order of creation: first created -> highest priority.
- # See how all your routes lay out with "rake routes".
-
- # You can have the root of your site routed with "root"
- # root 'welcome#index'
-
- # Example of regular route:
- # get 'products/:id' => 'catalog#view'
-
- # Example of named route that can be invoked with purchase_url(id: product.id)
- # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
-
- # Example resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Example resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Example resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Example resource route with more complex sub-resources:
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', on: :collection
- # end
- # end
-
- # Example resource route with concerns:
- # concern :toggleable do
- # post 'toggle'
- # end
- # resources :posts, concerns: :toggleable
- # resources :photos, concerns: :toggleable
-
- # Example resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
+ resources :notes, :except => [:new, :edit]
end
diff --git a/db/migrate/20150124004310_create_notes.rb b/db/migrate/20150124004310_create_notes.rb
new file mode 100644
index 0000000..41fe6cb
--- /dev/null
+++ b/db/migrate/20150124004310_create_notes.rb
@@ -0,0 +1,10 @@
+class CreateNotes < ActiveRecord::Migration
+ def change
+ create_table :notes do |t|
+ t.string :title
+ t.text :body
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644
index 0000000..30e0d1a
--- /dev/null
+++ b/db/schema.rb
@@ -0,0 +1,23 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended that you check this file into your version control system.
+
+ActiveRecord::Schema.define(version: 20150124004310) do
+
+ create_table "notes", force: :cascade do |t|
+ t.string "title"
+ t.text "body"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+end
diff --git a/test/controllers/notes_controller_test.rb b/test/controllers/notes_controller_test.rb
new file mode 100644
index 0000000..2a3800c
--- /dev/null
+++ b/test/controllers/notes_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class NotesControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/fixtures/notes.yml b/test/fixtures/notes.yml
new file mode 100644
index 0000000..e192dee
--- /dev/null
+++ b/test/fixtures/notes.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ title: MyString
+ body: MyText
+
+two:
+ title: MyString
+ body: MyText
diff --git a/test/models/note_test.rb b/test/models/note_test.rb
new file mode 100644
index 0000000..7bbab53
--- /dev/null
+++ b/test/models/note_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class NoteTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end