No release in over a year
Administrate has_many field extension to only use certain fields in a has_many collection
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Administrate::Field::HasManyWithFields

An administrate plug-in designed to allow you to only show certain fields when rendering a has_many relationship instead of rendering entire collection's dashboard. Extends the Administrate::Field::HasMany field.

Installation

Add this line to your application's Gemfile:

gem 'administrate-field-has_many_with_fields', '~> 0.1.1'

And then execute:

$ bundle install

Usage

Turn the standard has_many relationship in your administrate dashboard from this

class UserDashboard < Administrate::BaseDashboard
  # ATTRIBUTE_TYPES
  # a hash that describes the type of each of the model's fields.
  #
  # Each different type represents an Administrate::Field object,
  # which determines how the attribute is displayed
  # on pages throughout the dashboard.
  ATTRIBUTE_TYPES = {
    posts: Field::HasMany,
    # ...
  }

into this

class UserDashboard < Administrate::BaseDashboard
  # ATTRIBUTE_TYPES
  # a hash that describes the type of each of the model's fields.
  #
  # Each different type represents an Administrate::Field object,
  # which determines how the attribute is displayed
  # on pages throughout the dashboard.
  ATTRIBUTE_TYPES = {
    posts: Field::HasManyWithFields.with_options(fields: [:id, :attr_1, :attr_2, :method_1]),
    # ...
  }

The standard administrate with_options method (limit, class_name, etc) still works because this inherits from Administrate::Field::HasMany. The fields array also works with both model attributes and model methods.

License

The gem is available as open source under the terms of the MIT License.