Sha256: 63069d4ced399ba687526c2e981b6778be03c6b0040050746b86b053ec2ff82f

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

class BooksController < ApplicationController

  before_filter :find_book, :only => [:show, :edit, :update, :destroy]

  def index
    @books = Book.all
  end

  def show
  end

  def new
    @book = Book.new
  end

  def create
    @book = Book.new(books_params)
    if @book.save
      redirect_to books_path
    else
      flash[:notice] = "failed to create book"
      render :new
    end
  end

  def edit
  end

  def update
    if rails_4?
      method = :update
    else
      method = :update_attributes
    end
    if @book.send(method, books_params)
      redirect_to book_path(@book)
    else
      flash[:notice] = "failed to update book"
      render :edit
    end
  end

  def destroy
    if @book.destroy
      redirect_to books_path
    else
      flash[:notice] = "failed to destroy book"
      redirect_to book_path(@book)
    end
  end

  private

  def books_params
    if rails_4?
      params.require(:book).permit!
    else
      params[:book]
    end
  end

  def find_book
    @book = Book.find(params[:id])
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fastly-rails-0.1.0 test/dummy/app/controllers/books_controller.rb