문제

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]}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top