-
-
Save mt9304/f8deb96abb3acc0f64d30c47716143e5 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 | |
load_and_authorize_resource | |
before_action :authenticate_user!, except: [:index] | |
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 article_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