Sha256: 23bea4d32ef05b690074e46b76638666ef5e9af42344d4a1a13e2dd7764aeabc

Contents?: true

Size: 1.64 KB

Versions: 6

Compression:

Stored size: 1.64 KB

Contents

module InheritedResources
  # Holds all default actions for InheritedResouces.
  module Actions

    # GET /resources
    def index(options={}, &block)
      respond_with(*(with_chain(collection) << options), &block)
    end
    alias :index! :index

    # GET /resources/1
    def show(options={}, &block)
      respond_with(*(with_chain(resource) << options), &block)
    end
    alias :show! :show

    # GET /resources/new
    def new(options={}, &block)
      respond_with(*(with_chain(build_resource) << options), &block)
    end
    alias :new! :new

    # GET /resources/1/edit
    def edit(options={}, &block)
      respond_with(*(with_chain(resource) << options), &block)
    end
    alias :edit! :edit

    # POST /resources
    def create(options={}, &block)
      object = build_resource

      if create_resource(object)
        options[:location] ||= resource_url rescue nil
      end

      respond_with_dual_blocks(object, options, &block)
    end
    alias :create! :create

    # PUT /resources/1
    def update(options={}, &block)
      object = resource

      if update_resource(object, params[resource_instance_name])
        options[:location] ||= resource_url rescue nil
      end

      respond_with_dual_blocks(object, options, &block)
    end
    alias :update! :update

    # DELETE /resources/1
    def destroy(options={}, &block)
      object = resource
      options[:location] ||= collection_url rescue nil

      destroy_resource(object)
      respond_with_dual_blocks(object, options, &block)
    end
    alias :destroy! :destroy

    # Make aliases protected
    protected :index!, :show!, :new!, :create!, :edit!, :update!, :destroy!
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
karsthammer-inherited_resources-1.1.2.1 lib/inherited_resources/actions.rb
karsthammer-inherited_resources-1.1.2 lib/inherited_resources/actions.rb
inherited_resources-1.1.2 lib/inherited_resources/actions.rb
inherited_resources-1.0.6 lib/inherited_resources/actions.rb
inherited_resources-1.0.5 lib/inherited_resources/actions.rb
inherited_resources-1.0.4 lib/inherited_resources/actions.rb