Repository is archived
No commit activity in last 3 years
No release in over 3 years
Adds an Administrate::Field::SelectBasic for creating dropdown selects in your dashboards.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 10.0
~> 3.0

Runtime

>= 0.1.5, ~> 0.1
 Project Readme

Administrate::Field::Select

Adds basic select/dropdown fields to ThoughtBot's Administrate

Gem Version Build Status

NOTE: Since v0.1.15, Administrate now supports its own Field::Select with a slightly different mechanic. So this has been renamed to Field::SelectBasic. Please update your Gemfiles (as below) and rename your calls to this field.

Installation

Add this line to your application's Gemfile:

gem 'administrate-field-select', '~> 2.0', require: 'administrate/field/select_basic'

And then execute:

$ bundle

Usage

In your dashboard's ATRRIBUTE_TYPES, use the type Field::SelectBasic with options:

ATTRIBUTE_TYPES = {
  my_field: Field::SelectBasic.with_options({
    choices: ['option_one', 'option_two', 'option_three']
  }),
  some_other_field: Field::String,
}

The options specified in choices will be passed as the choice to a Rails select tag.

Additional options that are available:

  • include_blank: If true or a string, includes a blank option in the dropdown (with the string as its text).
  • prettify: If true, passes all choices through titleize before displaying them (in all views). If a lambda, that lambda is used instead of titleize.
  • i18n: If true, passes all choices through i18n before displaying them (in all views).

If both prettify and i18n are specified then prettify takes precedence.

Todo

Some ideas for possible enhancements:

  1. Be more magic with enum types and reflect the choices

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/fishpercolator/administrate-field-select. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

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