Sha256: 6c95a67d80a271125e2cfa34f7cfd1f03f2aeb1e1db6cd1ed603c491d1b70433

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

require 'gem_patching'
require 'inherited_resources'

Gem.patching('inherited_resources', '1.1.2') do
  InheritedResources::Actions.module_eval do
    module Actions
      def index(options={}, &block)
        respond_with(*(with_chain(resource_class) << options), &block)
      end
      alias :index! :index
    end
  end

  InheritedResources::BaseHelpers.module_eval do
    def collection
      get_collection_ivar || begin
        collection = end_of_association_chain
        collection = collection.find(:all) unless collection.respond_to?(:each)
        set_collection_ivar(collection)
      end
    end

    def build_resource
      get_resource_ivar || begin
        resource = end_of_association_chain.send(method_for_build, params[resource_instance_name] || {})
        # check if resource is included to prevent deleting from a relation
        if method_for_build == :build && end_of_association_chain.include?(resource)
          end_of_association_chain.delete(resource)
        end
        set_resource_ivar(resource)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adva-core-0.0.6 lib/patches/inherited_resources.rb
adva-core-0.0.5 lib/patches/inherited_resources.rb
adva-core-0.0.4 lib/patches/inherited_resources.rb