Rails_admin graphics breaks with enum attributes introduced in Rails 4.1

Rails 4.1 introduced enumerations that break rails_admin . Any solutions or work around?

My model includes the following line at the top

enum category: {industry: 1, company: 2, event: 3}

My gemfile has the following line

gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git'

There is no other code related to this problem. I have not changed the default rails_admin behavior. Below are the errors that occur when trying to change any model that contains the enum attribute through the rails_admin interface.

ArgumentError - '3' is not a valid category:
  activerecord (4.1.1) lib/active_record/enum.rb:103:in `block (3 levels) in enum'
  activerecord (4.1.1) lib/active_record/attribute_assignment.rb:45:in `_assign_attribute'
  activerecord (4.1.1) lib/active_record/attribute_assignment.rb:32:in `block in assign_attributes'
  activerecord (4.1.1) lib/active_record/attribute_assignment.rb:26:in `assign_attributes'
   () Users/nicolas/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/rails_admin-1d604b22d24c/lib/rails_admin/adapters/active_record/abstract_object.rb:19:in `set_attributes'
   () Users/nicolas/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/rails_admin-1d604b22d24c/lib/rails_admin/config/actions/edit.rb:29:in `block (2 levels) in <class:Edit>'
  (eval):8:in `edit'
  actionpack (4.1.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.1.1) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.1.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.1.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  [...]

What happens is that rails_admin does not recognize enumerations, but in its interface it displays them as numbers instead of strings. Then, when you click the "Save" button, it throws an exception above.

+4

Source: https://habr.com/ru/post/1545530/


All Articles