admin_resources 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ab15134c08ae8f5094ad4aaff7993db9e87ba6f2ae68301230ab08077e1014ca
|
|
4
|
+
data.tar.gz: a9e1c2480b2ab1458e94411421d17ab9fd109eb3a7aa971e4cc41a9d677d253a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4acb95d1ea8994ee3c20ec9b19e5cbb70fee88efa77a0f8bb9b0eb780e41a9f67fae66ec64f6003da4194e26b633d94ad4ac5c4d6e2dfef0dbd48c69675376b1
|
|
7
|
+
data.tar.gz: ee66d605c642c8489e80ba5a7efad43f20e1ca8b82fec790ff9d6b6e2df2e1089ba286ab443cba21449f2263f011d654a71caf972a66f55aa70315b311d9e1a4
|
|
@@ -3,7 +3,7 @@ module AdminResources
|
|
|
3
3
|
before_action :set_model_class
|
|
4
4
|
before_action :set_resource, only: %i[show edit update destroy custom_action]
|
|
5
5
|
|
|
6
|
-
helper_method :model_class, :model_name, :index_columns, :form_columns, :admin_value_display, :join_associations, :custom_actions, :filter_columns
|
|
6
|
+
helper_method :model_class, :model_name, :index_columns, :form_columns, :admin_value_display, :join_associations, :custom_actions, :filter_columns, :attachment_reflections
|
|
7
7
|
|
|
8
8
|
def index
|
|
9
9
|
puts "[AdminResources::ResourcesController] index for #{model_name}"
|
|
@@ -109,6 +109,12 @@ module AdminResources
|
|
|
109
109
|
model_class.column_names - %w[id created_at updated_at]
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
+
def attachment_reflections
|
|
113
|
+
return [] unless model_class.respond_to?(:reflect_on_all_attachments)
|
|
114
|
+
|
|
115
|
+
model_class.reflect_on_all_attachments
|
|
116
|
+
end
|
|
117
|
+
|
|
112
118
|
# Returns [display_text, link_path_or_nil]
|
|
113
119
|
def admin_value_display(resource, column)
|
|
114
120
|
unless resource.respond_to?(column)
|
|
@@ -148,6 +154,13 @@ module AdminResources
|
|
|
148
154
|
col.to_sym
|
|
149
155
|
end
|
|
150
156
|
end
|
|
157
|
+
attachment_reflections.each do |reflection|
|
|
158
|
+
if reflection.macro == :has_many_attached
|
|
159
|
+
permitted << { reflection.name => [] }
|
|
160
|
+
else
|
|
161
|
+
permitted << reflection.name
|
|
162
|
+
end
|
|
163
|
+
end
|
|
151
164
|
params.require(model_class.model_name.param_key).permit(*permitted)
|
|
152
165
|
end
|
|
153
166
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<%= form_with model: @resource, url: (@resource.new_record? ? admin_path_for(model_name, :index) : admin_path_for(model_name, :show, @resource)), class: "admin-form" do |form| %>
|
|
1
|
+
<%= form_with model: @resource, url: (@resource.new_record? ? admin_path_for(model_name, :index) : admin_path_for(model_name, :show, @resource)), class: "admin-form", html: { multipart: attachment_reflections.any? } do |form| %>
|
|
2
2
|
<% if @resource.errors.any? %>
|
|
3
3
|
<div class="admin-flash alert">
|
|
4
4
|
<strong><%= pluralize(@resource.errors.count, "error") %> prohibited this <%= model_name.downcase %> from being saved:</strong>
|
|
@@ -59,6 +59,17 @@
|
|
|
59
59
|
</div>
|
|
60
60
|
<% end %>
|
|
61
61
|
|
|
62
|
+
<% attachment_reflections.each do |reflection| %>
|
|
63
|
+
<div class="field">
|
|
64
|
+
<%= form.label reflection.name %>
|
|
65
|
+
<% if reflection.macro == :has_many_attached %>
|
|
66
|
+
<%= form.file_field reflection.name, multiple: true %>
|
|
67
|
+
<% else %>
|
|
68
|
+
<%= form.file_field reflection.name %>
|
|
69
|
+
<% end %>
|
|
70
|
+
</div>
|
|
71
|
+
<% end %>
|
|
72
|
+
|
|
62
73
|
<% join_associations.each do |jdef| %>
|
|
63
74
|
<% assoc_name = jdef[:association] %>
|
|
64
75
|
<% param_key = "#{assoc_name}_ids" %>
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: admin_resources
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- mark rosenberg
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|