Skip to content

Commit

Permalink
Fixed: support ActiveRecord::Enum
Browse files Browse the repository at this point in the history
To get selector's item, Typus uses plualized name's method.
https://github.com/typus/typus/wiki/customization-selectors

But, when Rails4.1 released. Method name confilected
ActiveRecord::Enum's method name.
so, I research other admin framework gems, and I think best way to
implement enum selector.

1. rails_admin
rails_admin select new method name is like "{column name}_enum"
railsadminteam/rails_admin#1993

2. active admin
active admin select add to parameter in "collection" option.
http://stackoverflow.com/questions/23414880/how-to-properly-configure-rails-4-1-enums-in-activeadmin

and, ActiveRecord::Enum have't I18n. so liker a below gems were released
to support this function.

* https://github.com/brainspec/enumerize
* https://github.com/zmbacker/enum_help

so, We should avoid ActieRecord::Enum i18n gem's implement and use
convenient.
I'll follow rails_admin's way.
  • Loading branch information
baban committed Feb 6, 2017
1 parent b26adf5 commit acd0a20
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/admin/templates/_selector.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="form-group" id="<%= attribute_id %>">
<%= form.label attribute, label_text, { class: 'control-label' } %>
<%= form.select attribute, @resource.send(attribute.pluralize), options, { class: 'form-control' } %>
<%= form.select attribute, @resource.try("#{attribute.pluralize}_enum") || @resource.send(attribute.pluralize), options, { class: 'form-control' } %>
</div>

0 comments on commit acd0a20

Please sign in to comment.