Sha256: 54897e5923fcdd48c30c61118bbe361b3025571ce4f906e3f4f1365ae18c99fa

Contents?: true

Size: 845 Bytes

Versions: 6

Compression:

Stored size: 845 Bytes

Contents

class AuthorsController < ApplicationController
  def index
    @authors = Author.order(created_at: :desc)
  end

  def new
    @author = Author.new
  end

  def edit
    @author = Author.find params[:id]
  end

  def update
    @author = Author.find params[:id]

    if @author.update author_params
      flash[:success] = "Updated author"
      redirect_to author_books_path(@author)
    else
      render :edit
    end
  end

  def destroy
    @author = Author.find params[:id]
    @author.delete_books
    @author.destroy
    redirect_to authors_path
  end

  def create
    @author = Author.new author_params

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

  private

  def author_params
    params.require(:author).permit(:name)
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

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