Skip to content

Form & Table Field Reference

Seoung Ho Jeong edited this page Jun 29, 2024 · 4 revisions

Reference

Table

The table DSL accepts the following methods:

column(field, proc=nil, options={}, &block) # Adds a column with the given field name to the table.
actions(options={}, &block)                 # Appends default actions and additional actions for table entries (e.g. delete)
row(options={}, &block)                     # Unclear what this does
selectable_column(options={})               # Adds a column by which table rows can be selected

Column

If no proc/block are given, then the field name is used as the database field name.

If a proc or block is given, this is passed the instance to return the value to show. Please note that if you perform any database access here, these are going to be executed for each instance (row) which is currently visible in the table. This is also the reason why sorting is not available when you use proc or block (it would have to evaluate the result for each database entry).

If both a proc and block are given, the proc takes precedence.

Options:

  • align
  • link
  • sort

TODO

Forms

Text Field

text_field :caption

Select Field

(With bonus enum handling)

resource_states = Resource.states.keys.map { |state| [state.humanize, state] }
select :state, resource_states

with selected value

resource_states = Resource.states.keys.map { |state| [state.humanize, state] }
select :state, resource_states, { selected: resource.state }

Static Field

static_field :updated_at, resource.updated_at

CheckBox Field

check_box :is_true?

Email Field

email_field :email

Telephone Field

telephone_field :mobile

Collection CheckBoxes

collection_check_boxes :resource_ids, Resource.all, :id, :name

Collection Radio Buttons

collection_radio_buttons :resource_id, Resource.all, :id, :name

Collection Select

collection_select :resource_id, Resource.all, :id, :name

optional

{ multiple: true }

Color Field

color_field :paint_color

Date Field

date_field :date_from

Date Select

date_select :date_to

DateTime Field

datetime_field :game_start

DateTime Select

datetime_select :game_start

File Field

file_field :image

To allow multiple files to be uploaded:

file_field :attachments, multiple: true

The file_field helper works the same as the corresponding Rails form helper (Source: Issue 272).

Month Field

month_field :season_start

Number Field

number_field :group_size

Password Field

password_field :password

Tag Select

 tag_select :post_tags

Text Area

 text_area :content

Time Field

 time_field :start_at

Time Select

 time_select :start_at

Time Zone Select

 time_zone_select :current_time_zone

URL Field

 url_field :site_url

Week Field

 week_field :during_week