Sha256: 5e2192967253d37017fee7dea789d4dd2ffc94808afe54630349f8fd56f86ed3

Contents?: true

Size: 1.18 KB

Versions: 13

Compression:

Stored size: 1.18 KB

Contents

require 'responders'
require 'inherited_resources'
require 'inherited_resources/actions'
require 'inherited_resources/responder'

module InheritedResources
  # redirect to edit_resource_url instead of resource_url
  module Actions

    def create(options={}, &block)
      object = build_resource

      if create_resource(object)
        options[:location] ||= edit_resource_url rescue nil # change here
      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] ||= edit_resource_url rescue nil # change here
      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)

      options[:alert] = object.errors.full_messages.first # display the first error if present

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

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
locomotive_cms-1.0.0.beta.2 lib/locomotive/inherited_resources.rb
locomotive_cms-1.0.0.beta lib/locomotive/inherited_resources.rb
locomotive_cms-0.0.4.beta12 lib/locomotive/inherited_resources.rb
locomotive_cms-0.0.4.beta11 lib/locomotive/inherited_resources.rb
locomotive_cms-0.0.4.beta10 lib/locomotive/inherited_resources.rb
locomotive_cms-0.0.4.beta9 lib/locomotive/inherited_resources.rb
locomotive_cms-0.0.4.beta8 lib/locomotive/inherited_resources.rb
locomotive_cms-0.0.4.beta7 lib/locomotive/inherited_resources.rb
locomotive_cms-0.0.4.beta5 lib/locomotive/inherited_resources.rb
locomotive_cms-0.0.4.beta4 lib/locomotive/inherited_resources.rb
locomotive_cms-0.0.4.beta3 lib/locomotive/inherited_resources.rb
locomotive_cms-0.0.4.beta2 lib/locomotive/inherited_resources.rb
locomotive_cms-0.0.4.beta1 lib/locomotive/inherited_resources.rb