Relationships are handled in the :user_columns declarations just like other column types. So, in the example below, Team has_one :coach. In this case, the :show_view is called :name and combines the :first_name and :last_name fields of the :coach instance using an empty space and uses that value as the column contents. The :edit_view is called :select, which is the default, and creates a dropdown. You could use the same modifiers (:fields and :separator) to populate the dropdown with customized values.
Streamlined.ui_for(Team) do
user_columns :id, {:read_only => true},
:name, {:link_to => {:action => "edit"}},
:sport, {:popup => true},
:coach, {
:show_view => [:name,
{ :fields => [:first_name, :last_name], :separator => " " },
],
:edit_view => [:select]}
end
There are many available :show_ and :edit_views, plus the model is extensible. Here are the currently available versions.
Show Views
| Name | Use | Available |
| Link | Link to related table | All |
| Count | Shows number of related items | 1-to-n |
| List | Display data from related models | 1-to-n |
| Sum | Calculate sum of field on related items | 1-to-n |
| Average | Calculate average of field on related items | 1-to-n |
| Name | Display data from related item | n-to-1 |
| Enumerable | Treat association as an enumerable | n-to-1 |
| Graph | Display sparklines graph of related items | 1-to-n |
The default for show-views for a 1-to-n relationship is count, and for a 1-to-1 is name.
Edit Views
| Name | Use | Available |
| Inset Table | Master-detail view | Any |
| Membership | Allows user to select items | 1-to-n |
| Polymorphic Membership | Allows user to select related items of polymorphic relationship | 1-to-n |
| Window | Shows related items in table in popup window | 1-to-n |
| Select | Select related item from dropdown | n-to-1 |
| Polymorphic Select | Select related polymorphic item from dropdown | n-to-1 |
| Enumerable Select | Treat association as an enumerable | n-to-1 |
| Filter Select | Like membership, but uses Ajax to allow filtering of possible matches | 1-to-n |
