Sha256: 851a712a5b58d780c074c3b874e91a2cfbbb0d1092145c716c5455144f6125dc

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

# Provides CRUD actions for +Author+ model.

require_dependency "lines/admin/application_controller"

module Lines
  module Admin
    class AuthorsController < ApplicationController

      # Listes all authroes
      def index
        @authors = Lines::Author.all
      end

      # Shows an author
      def show
        @author = Lines::Author.find(params[:id])
      end

      # New author
      def new
        @author = Lines::Author.new
      end

      # Edit an existing author
      def edit
        @author = Lines::Author.find(params[:id])
      end

      # Create a new author from params
      def create
        @author = Lines::Author.new(author_params)

        if @author.save
          redirect_to admin_author_path @author
        else
          render action: "new"
        end
      end

      # Update an existing author from params
      def update
        @author = Lines::Author.find(params[:id])

        if @author.update_attributes(author_params)
          redirect_to admin_author_path(@author)
        else
          render action: "edit"
        end
      end

      # Delete an author
      def destroy
        @author = Lines::Author.find(params[:id])
        if @author.destroy
          redirect_to admin_authors_url
        else
          @authors = Lines::Author.all
          render "index" 
        end
      end

      private

        # Use strong_params
        def author_params
          params.require(:author).permit(:email, :name, :description, :gplus_profile)
        end
    end

  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
jeygeethanmedia-inkpen-1.2.6.2 app/controllers/lines/admin/authors_controller.rb
jeygeethanmedia-inkpen-1.2.6.1 app/controllers/lines/admin/authors_controller.rb
lines-engine-1.2.6.1 app/controllers/lines/admin/authors_controller.rb
lines-engine-1.2.6 app/controllers/lines/admin/authors_controller.rb
lines-engine-1.2.5 app/controllers/lines/admin/authors_controller.rb