Sha256: 3d7fb287de58f4057ed8137eaffa23e1de18bc12e376e0d4b73a2ec460bbb404

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

class BooksController < ApplicationController
  before_filter :set_cache_control_headers, only: [:index, :show]
  before_filter :find_book, :only => [:show, :edit, :update, :destroy]

  def index
    @books = Book.all
    set_surrogate_key_header 'books', @books.map(&:record_key)
  end

  def show
    set_surrogate_key_header @book.record_key
  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

12 entries across 12 versions & 1 rubygems

Version Path
fastly-rails-0.8.0 test/dummy/app/controllers/books_controller.rb
fastly-rails-0.7.1 test/dummy/app/controllers/books_controller.rb
fastly-rails-0.7.0 test/dummy/app/controllers/books_controller.rb
fastly-rails-0.6.0 test/dummy/app/controllers/books_controller.rb
fastly-rails-0.5.0 test/dummy/app/controllers/books_controller.rb
fastly-rails-0.4.1 test/dummy/app/controllers/books_controller.rb
fastly-rails-0.4.0 test/dummy/app/controllers/books_controller.rb
fastly-rails-0.3.0 test/dummy/app/controllers/books_controller.rb
fastly-rails-0.2.0 test/dummy/app/controllers/books_controller.rb
fastly-rails-0.1.7 test/dummy/app/controllers/books_controller.rb
fastly-rails-0.1.6 test/dummy/app/controllers/books_controller.rb
fastly-rails-0.1.5 test/dummy/app/controllers/books_controller.rb