Rails_Admin static select dropdown
-
27-04-2021 - |
Вопрос
I want to be able to use a static drop down in some of my forms, for example:-
car body type
Hatchback Saloon Coupe
any help with this would be great.
Решение
I managed to do it by putting this in my model;
def body_type_enum
['Hatchback', 'Saloon', 'Estate', 'Convertible', 'MVP', 'Coupe', '4X4']
end
Другие советы
The above did not work for me. Here is the working version of my code (Rails 3.1.3, RailsAdmin 0.0.1)
[['Item 1'], ['Item 2'], ['Item 3']]
If you want the option value to be different you can do like:
[['Item 1','item1'], ['Item 2','item2'], ['Item 3','item3']]
For dynamic collection, we can write this way:
forms = {item1: 'Item 1', item2: 'Item 2', item3: 'Item 3'}
forms.map{|key, val| [val, key]}
Не связан с StackOverflow