Reputation: 6915
I am using Rails Admin gem (Ruby On Rails) and I need to show a dropdown field on one form.
I check about adding Enum method to Class definition from sample here:
But this is not working in my case:
the result I am getting are values inside textbox not in dropdown .
What am I doing wrong here ?
Upvotes: 2
Views: 5216
Reputation: 2434
Here is an official documentation for Rails Admin Enumeration.
It states that If you already have a database column for which you want a dropdown then simple add a method COLUM_NNAME_enum
and every thing will be taken care off. e.g
If you want a dropdown for status
column then you need to define a status_enum
method in your model.
Other approach is directly telling the field
that we wanna use enum
for this field so there are 2 options to do that.
class Test << ActiveRecord::Base
rails_admin do
create do
field :status , :enum do
enum_method do
:status_enum
end
end
end
end
#Here is other simple option
rails_admin do
create do
field :status , :enum do
enum do
[['Actice',1],['Pending',0]]
end
end
end
end
end
Upvotes: 6