-
-
Save mt9304/bd76031fe933b833beffd29e9af538dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Api | |
class BooksController < ApplicationController | |
def index | |
render json: Book.all | |
end | |
def new | |
@book = Book.new | |
end | |
def create | |
book = Book.new(book_params) | |
if book.save | |
render json: book | |
else | |
render nothing: true, status: :bad_request | |
end | |
end | |
def update | |
if @book.update(book_params) | |
render json: @book | |
else | |
render nothing: true, status: :unprocessable_entity | |
end | |
end | |
def show | |
@book = Book.find(params[:id]) | |
render json: @book | |
end | |
def destroy | |
@book.destroy | |
head :no_content | |
end | |
private | |
def book_params | |
params.permit(:book, :title, :author, :description, :pages, :published) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment