Sha256: 860d2b5c3936838f4589cb972f22a1c183ccd9a1dcf0c5baef01182d26f859e0

Contents?: true

Size: 695 Bytes

Versions: 46

Compression:

Stored size: 695 Bytes

Contents

require 'active_support/concern'

module ResourceRow
  module AssociationExtensions
    extend ActiveSupport::Concern

    def association(association_name, options = {})
      options.reverse_merge!(label_method: :name)
      label_method = options.delete(:label_method)
      associated = resource.send(association_name)

      label = associated.respond_to?(label_method) ? associated.send(label_method) : nil

      if label.present?
        link_method_name = "#{associated.class.name.demodulize.underscore}_path"
        column(association_name) { |_resource| h.link_to(label, h.send(link_method_name, associated)) }
      else
        column(association_name)
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
itsf_backend-5.0.0.pre app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-4.2.3 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-4.2.2 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-4.2.1 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-4.2.0 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-4.0.1 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-4.0.0 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-3.1.1 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-3.1.0 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-3.0.7 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-3.0.6 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-3.0.5 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-3.0.4 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-3.0.3 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-3.0.2 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-3.0.1 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-3.0.0 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-2.2.1 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-2.2.0 app/extensions/concerns/resource_row/association_extensions.rb
itsf_backend-2.1.0 app/extensions/concerns/resource_row/association_extensions.rb