Skip to content

Instantly share code, notes, and snippets.

@bridgpal
Created August 25, 2014 23:07
Show Gist options
  • Save bridgpal/99b5923c948c11190acb to your computer and use it in GitHub Desktop.
Save bridgpal/99b5923c948c11190acb to your computer and use it in GitHub Desktop.
class BooksController < ApplicationController
before_action :set_book, only: [:show, :update, :destroy]
respond_to :json
def index
respond_with Book.all
end
def create
respond_with Book.create(book_params)
end
def show
respond_with @book
end
def update
respond_with @book.update(book_params)
end
def destroy
respond_with @book.destroy
end
private
def set_book
@book = Book.find(params[:id])
end
def book_params
params.require(:book).permit(:title, :author, :description, :isbn)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment