Sha256: b6e157b9d76fc71036834102f72dfb8ab85015dc87bee3da601fd854b3d96223

Contents?: true

Size: 816 Bytes

Versions: 1

Compression:

Stored size: 816 Bytes

Contents

module Para
  module Component
    module CrudDecorator
      include Para::Component::BaseDecorator

      def relation_path(controller_or_resource, options = {})
        if (id = extract_id_from(controller_or_resource))
          options[:id] = id
        end

        route_key = route_key_for(options[:id], options)
        options[:model] = model.model_name.singular_route_key

        polymorphic_path([:admin, self, route_key].compact, options)
      end

      private

      def extract_id_from(object)
        object.id if object.respond_to?(:persisted?) && object.persisted?
      end

      def route_key_for(id, options)
        if id || options[:action].presence && options[:action].to_sym == :new
          :crud_resource
        else
          :crud_resources
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
para-0.4.0 app/decorators/para/component/crud_decorator.rb