Guest User

Untitled

a guest
Feb 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.58 KB | None | 0 0
  1. class BooksController < ApplicationController
  2.   # GET /books.json
  3.   def index
  4.     books = Book.all
  5.     render :json => books
  6.   end
  7.  
  8.   # GET /books/7.json
  9.   def show
  10.     book = Book.find(params[:id])
  11.     render :json => book
  12.   end
  13.  
  14.   # POST /books
  15.   def create
  16.     book = Book.new(params[:book])
  17.     if book.save
  18.       render :status => 200
  19.     else
  20.       render what ever validation error or message you want
  21.     end
  22.   end
  23.  
  24.   # PUT /books/7
  25.   def update
  26.     book = Book.find(params[:id])
  27.     book.update_attributes(params[:book])
  28.     if book.save
  29.     ....
  30.   end
  31. end
Add Comment
Please, Sign In to add comment