Sha256: cc40d4168960b55fd447da8e9a67f22462c4a863c107857f3df7d024b81e25a8

Contents?: true

Size: 999 Bytes

Versions: 6

Compression:

Stored size: 999 Bytes

Contents

class BooksController < ApplicationController
  before_action :set_author, only: [:index, :new, :create]
  before_action :set_book, only: [:show, :edit, :update, :destroy]

  def index
    @books = @author.books
  end

  def new
    @book = Book.new
  end

  def show
  end

  def edit
    @author = @book.author
  end

  def update
    if @book.update book_params
      flash[:success] = "Updated book"
      redirect_to book_path(@book)
    else
      render :edit
    end
  end

  def destroy
    @author = @book.author
    @book.destroy
    redirect_to author_books_path(@author)
  end

  def create
    @book = @author.books.new book_params

    if @book.save
      flash[:success] = "Added book"
      redirect_to book_path(@book)
    else
      render :new
    end
  end

  private

  def set_author
    @author = Author.find params[:author_id]
  end

  def set_book
    @book = Book.find params[:id]
  end

  def book_params
    params.require(:book).permit(:title, :description)
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gdatastore_mapper-0.1.8 rails_example/app/controllers/books_controller.rb
gdatastore_mapper-0.1.7 rails_example/app/controllers/books_controller.rb
gdatastore_mapper-0.1.6 rails_example/app/controllers/books_controller.rb
gdatastore_mapper-0.1.5 rails_example/app/controllers/books_controller.rb
gdatastore_mapper-0.1.4 rails_example/app/controllers/books_controller.rb
gdatastore_mapper-0.1.3 rails_example/app/controllers/books_controller.rb