Sha256: d44a57d7c9331c3f42c8d852d466f8ba4a027cad45608c832c5adbea7175eb98

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 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

1 entries across 1 versions & 1 rubygems

Version Path
outpost-cms-0.0.3 lib/outpost/controller/actions.rb