Sha256: 1fb6c42161075cde2eab089614148344a98494053c17f960c419684bc7dcdf56

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

class BooksController < ApplicationController
  before_action :set_book, only: [:show, :update, :destroy]

  include Yamls::Support::Parameters

  # GET /books
  def index
    @books = Book.all

    render json: @books
  end

  # GET /books/1
  def show
    render json: @book
  end

  # POST /books
  def create
    @book = Book.new(book_params)

    if @book.save
      render json: @book, status: :created, location: @book
    else
      render json: @book.errors, status: :unprocessable_entity
    end
  end

  # PATCH/PUT /books/1
  def update
    if @book.update(book_params)
      render json: @book
    else
      render json: @book.errors, status: :unprocessable_entity
    end
  end

  # DELETE /books/1
  def destroy
    @book.destroy
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_book
      @book = Book.find(params[:id])
    end

    # Only allow a trusted parameter "white list" through.
    def book_params
      params.require(:book).permit(:name, :label, :value)
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yamls-0.2.2 example/rails5/app/controllers/books_controller.rb
yamls-0.2.1 example/rails5/app/controllers/books_controller.rb