Skip to content

Commit

Permalink
Support AR enums in resource models
Browse files Browse the repository at this point in the history
  • Loading branch information
robinboening committed Nov 5, 2021
1 parent eb50acb commit 6ed88ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/views/alchemy/admin/resources/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
input_html: {class: 'alchemy_selectbox'} %>
<% elsif attribute[:type].in? %i[date time datetime] %>
<%= f.datepicker attribute[:name], resource_attribute_field_options(attribute) %>
<% elsif attribute[:enum].present? %>
<%= f.input attribute[:name],
collection: attribute[:enum],
include_blank: Alchemy.t(:blank, scope: 'resources.relation_select'),
input_html: {class: 'alchemy_selectbox'} %>
<% else %>
<%= f.input attribute[:name], resource_attribute_field_options(attribute) %>
<% end %>
Expand Down
3 changes: 2 additions & 1 deletion lib/alchemy/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def attributes
name: col.name,
type: resource_column_type(col),
relation: resource_relation(col.name),
}.delete_if { |_k, v| v.nil? }
enum: model.defined_enums[col.name]&.keys
}.delete_if { |_k, v| v.blank? }
end.compact
end

Expand Down

0 comments on commit 6ed88ca

Please sign in to comment.