Rails 4.1 introduced enum attributes which don't behave well with RailsAdmin.
RailsAdmin (v 0.6.2) threats enum attributes as integers by default. This can be "fixed" by adding method to the model, ie.
enum status: [ :active, :archived ]
def status_enum
self.class.statuses.to_a
end
There is another issue - creating or updating record raises:
ArgumentError in RailsAdmin::MainController#new
'1' is not a valid state
Obviously the controller got '1' as a string value which doesn't match any of the states ('active', 'archived'), nor state as integer (0, 1).
The quick fix might look like:
def status= value
if value.kind_of?(String) and value.to_i.to_s == value
super value.to_i
else
super value
end
end
It works, but isn't nice. Especially when you have multiple enum attributes.
Looking forward to support for ActiveRecord::Enum out of the box.
Rails 4.1 introduced enum attributes which don't behave well with RailsAdmin.
RailsAdmin (v 0.6.2) threats enum attributes as integers by default. This can be "fixed" by adding method to the model, ie.
There is another issue - creating or updating record raises:
Obviously the controller got
'1'as a string value which doesn't match any of the states ('active','archived'), nor state as integer (0,1).The quick fix might look like:
It works, but isn't nice. Especially when you have multiple enum attributes.
Looking forward to support for
ActiveRecord::Enumout of the box.