Sha256: d06315d8c66bf4c656fbe771e74cb01120f758b6989bb81d6fba7c50cc018732

Contents?: true

Size: 1.4 KB

Versions: 16

Compression:

Stored size: 1.4 KB

Contents

module PolymorphicResourceConcern

  private

  def set_polymorphic_resource
    klasses = polymorphic_klasses.select do |c|
      params[c.to_s.foreign_key]
    end

    @nested_resources = nested_resources(klasses)
    # puts "nested_resources :::::::::::::::::::: #{@nested_resources}"
    # puts "resource_name:::::::::::::::::::: #{resource_name}"
    @polymorphic_resource_name = resource_name
  end

  def nested_resources(klasses)
    nested_resources = []
    last_klass_foreign_key = params[klasses.last.to_s.foreign_key]
    if klasses.is_a? Array
      @polymorphic_resource = klasses.last.find(last_klass_foreign_key)
      klasses.pop # remove @polymorphic_resource resource
      klasses.each do |klass|
        nested_resources.append klass.find(params[klass.to_s.foreign_key])
      end
    else
      @polymorphic_resource = klasses.find(params[klasses.to_s.foreign_key])
    end

    # prepend :admin for admin/namespacing
    nested_resources.prepend(:admin) if @polymorphic_resource.class == Gaku::Campus
    nested_resources
  end

  def resource_name
    resource_name = []
    @nested_resources.each do |resource|
      if resource.is_a?(Symbol)
        resource_name.append(resource.to_s)
      else
        resource_name.append(get_class(resource))
      end
    end
    resource_name.append get_class(@polymorphic_resource)
    resource_name.append resource_klass
    resource_name.join '-'
  end

end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
gaku_frontend-0.3.0 app/controllers/concerns/polymorphic_resource_concern.rb
gaku_frontend-0.3.0.pre.4 app/controllers/concerns/polymorphic_resource_concern.rb
gaku_frontend-0.3.0.pre.3 app/controllers/concerns/polymorphic_resource_concern.rb
gaku_frontend-0.3.0.pre.2 app/controllers/concerns/polymorphic_resource_concern.rb
gaku_frontend-0.3.0.pre.1 app/controllers/concerns/polymorphic_resource_concern.rb
gaku_frontend-0.3.0.pre.0 app/controllers/concerns/polymorphic_resource_concern.rb
gaku-0.2.4 frontend/app/controllers/concerns/polymorphic_resource_concern.rb
gaku_frontend-0.2.4 app/controllers/concerns/polymorphic_resource_concern.rb
gaku-0.2.3 frontend/app/controllers/concerns/polymorphic_resource_concern.rb
gaku_frontend-0.2.3 app/controllers/concerns/polymorphic_resource_concern.rb
gaku-0.2.2 frontend/app/controllers/concerns/polymorphic_resource_concern.rb
gaku_frontend-0.2.2 app/controllers/concerns/polymorphic_resource_concern.rb
gaku-0.2.1 frontend/app/controllers/concerns/polymorphic_resource_concern.rb
gaku_frontend-0.2.1 app/controllers/concerns/polymorphic_resource_concern.rb
gaku-0.2.0 frontend/app/controllers/concerns/polymorphic_resource_concern.rb
gaku_frontend-0.2.0 app/controllers/concerns/polymorphic_resource_concern.rb