app/views/shared/_fields.html.erb in zutils-0.3.9 vs app/views/shared/_fields.html.erb in zutils-0.4.0
- old
+ new
@@ -1,19 +1,30 @@
<% excluded_columns ||= [] %>
+<% additional_columns ||= [] %>
<% restricted_columns ||= {} %>
<% form_fields ||= (object.class.respond_to?('form_fields') ? object.class.form_fields : {}) %>
<% form_ordered_fields ||= (form_fields.empty? ? object.class.column_names : form_fields.keys) %>
<div class="row">
- <% (form_ordered_fields - ['id', 'created_at', 'updated_at', 'deleted_at'] - excluded_columns).each do |column| %>
+ <% (form_ordered_fields - ['id', 'created_at', 'updated_at', 'deleted_at'] - excluded_columns + additional_columns).each do |column| %>
<% wphtml = "col-md-#{(form_fields[column.to_sym].class == Hash ? form_fields[column.to_sym][:size] : form_fields[column.to_sym] ) || 12}" %>
<% hint = (form_fields[column.to_sym].class == Hash ? form_fields[column.to_sym][:hint] : '') %>
<% placeholder = (form_fields[column.to_sym].class == Hash ? form_fields[column.to_sym][:placeholder] : '') %>
<% if object.class.column_for_attribute(column).type == :text %>
<%= f.input column, input_html: { rows: 10, cols: 20 }, wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %>
<% elsif [:date, :datetime].include?(object.class.column_for_attribute(column).type) %>
<%= f.input column, html5: true, wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %>
+ <% elsif object.send(column).respond_to? 'attached?' %>
+ <% if object.send(column).class == ActiveStorage::Attached::Many %>
+ <%= f.input column, wrapper_html: { class: wphtml }, hint: hint, input_html: { multiple: true, class: 'fileinput',
+ data: {
+ initial: object.send(column).map{|im| rails_blob_path(im, only_path: true)}
+ }
+ } %>
+ <% else %>
+ <%= f.input column, wrapper_html: { class: wphtml }, hint: hint, input_html: { class: 'fileinput', 'data-initial': [rails_blob_path(object.send(column))] } %>
+ <% end %>
<% elsif /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
<% if restricted_columns.keys.include?(column.to_sym) %>
<%= f.association column.split("_id")[0],
label: restricted_columns[column.to_sym][:label],
collection: restricted_columns[column.to_sym][:collection],