Sha256: 60fd4f935e1f12927d5f990bbf5e81a67dd9a032af5eb02f03443b0c22d79314

Contents?: true

Size: 1.64 KB

Versions: 7

Compression:

Stored size: 1.64 KB

Contents

##
# Outpost::Controller::Actions
#
# This provides basic CRUD actions for you to include into any
# controller that you want to behave like a resource management
# area.
module Outpost
  module Controller
    module Actions
      def index
        respond_with :outpost, @records
      end

      def new
        breadcrumb "New"
        @record = model.new
        respond_with :outpost, @record
      end

      def show
        redirect_to @record.admin_edit_path
      end

      def edit
        breadcrumb "Edit", nil, @record.to_title
        respond_with :outpost, @record
      end

      def create
        @record = model.new(form_params)

        if @record.save
          notice "Saved #{@record.simple_title}"
          respond_with :outpost, @record, location: requested_location
        else
          breadcrumb "New"
          render :new
        end
      end

      def update
        if @record.update_attributes(form_params)
          notice "Saved #{@record.simple_title}"
          respond_with :outpost, @record, location: requested_location
        else
          breadcrumb "Edit", nil, @record.to_title
          render :edit
        end
      end

      def destroy
        @record.destroy
        notice "Deleted #{@record.simple_title}"
        respond_with :outpost, @record
      end

      private

      def form_params
        params[model.singular_route_key]
      end

      def requested_location
        case params[:commit_action]
        when "edit" then @record.admin_edit_path
        when "new"  then model.admin_new_path
        else model.admin_index_path
        end
      end
    end # Actions
  end # Controller
end # Outpost

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
outpost-cms-0.1.4 lib/outpost/controller/actions.rb
outpost-cms-0.1.3 lib/outpost/controller/actions.rb
outpost-cms-0.1.2 lib/outpost/controller/actions.rb
outpost-cms-0.1.1 lib/outpost/controller/actions.rb
outpost-cms-0.1.0 lib/outpost/controller/actions.rb
outpost-cms-0.0.5 lib/outpost/controller/actions.rb
outpost-cms-0.0.4 lib/outpost/controller/actions.rb