Sha256: 2f5036a6046bfa1e35c9fe6231426fca9002ff92af1c156ae5118a8c7ac51a00

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

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

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

  # GET /books/1
  def show
  end

  # GET /books/new
  def new
    @book = Book.new
  end

  # GET /books/1/edit
  def edit
  end

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

    if @book.save
      redirect_to @book, notice: 'Book was successfully created.'
    else
      render :new
    end
  end

  # PATCH/PUT /books/1
  def update
    if @book.update(book_params)
      redirect_to @book, notice: 'Book was successfully updated.'
    else
      render :edit
    end
  end

  # DELETE /books/1
  def destroy
    @book.destroy
    redirect_to books_url, notice: 'Book was successfully destroyed.'
  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(:title, :author, :summary)
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
librails-0.3.0 test/dummy/app/controllers/books_controller.rb
librails-0.2.3 test/dummy/app/controllers/books_controller.rb
librails-0.2.2 test/dummy/app/controllers/books_controller.rb
librails-0.2.1 test/dummy/app/controllers/books_controller.rb
librails-0.1.0 test/dummy/app/controllers/books_controller.rb