I'm trying to implement the following logic for the :value field: if :key == "test", then a drop-down list with two options ['option1', 'option2] is displayed in any other case, a normal line field is displayed.
I expected something like this:
#Table name: settings
#key :string
#value :string
class Setting < ApplicationRecord
extend Enumerize
rails_admin do
edit do
field :value do
formatted_value do
if bindings[:object].key == "test"
enum do
['option1', 'option2]']
end
else
bindings[:view].text_field(:value, value: value)
end
end
end
end
end
end
But this code does not work (for all fields it displays a drop-down list ['option1', 'option2]']) Tried something like this:
bindings[:view].select_tag("value",binding[:view].options_for_select(["1", "2"], value))
But there are problems in model with options_for_select.
I don’t want to edit view, but I want to do it better. I will be glad for any help!
The only working option I found is through attr_accessor:
If someone has a better idea, I would be glad to see it.