To conditionally display a field based on a value in the displayed object, you can do the following:
RailsAdmin.config do |config|
config.model YourObject do
edit do
field :some_random_attribute do
visible do
bindings[:object].your_conditional_field=="your_conditional_value"
end
end
end
end
end
In this Rails Admin configuration example, you can see that the YourObject#some_random_attribute field will only display if the YourObject object being displayed satisfies the condition within the “visible” block, otherwise it will not appear.
Small fix.
it should be:
field :some_random_attribute do
instead of:
field :some_random_attribute
Thanks Juan – the syntax has been updated.
Hi Anthony,
Thanks for your tutorial. I’m still struggling how my code will work. Please see below syntax. Thanks!
field :quantity do
visible do
bindings[:object].user_id == User.current.id
end
end
Hey I have tried this why I am getting nil when I try to access bindings[:object].your_conditional_field? Please help rails_admin is such a dig in the head thing.