Sha256: d65d1d128a30a4e97c43187ba6eef3d08e068fe6fdf34059b627e7fa4bbec904

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 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] ||= smart_resource_url
      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_request_name])
        options[:location] ||= smart_resource_url
      end

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

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

      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

2 entries across 2 versions & 1 rubygems

Version Path
inherited_resources-1.2.1 lib/inherited_resources/actions.rb
inherited_resources-1.2.0 lib/inherited_resources/actions.rb