generic_resources 0.1.3 → 0.1.9
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 +5 -5
- data/app/controllers/generic_resources/resources_controller.rb +8 -1
- data/app/views/generic_resources/_form.html.erb +9 -0
- data/app/views/generic_resources/resources/all.html.example.erb +0 -0
- data/app/views/generic_resources/resources/edit.html.erb +2 -4
- data/app/views/generic_resources/resources/index.example.html.erb +0 -0
- data/app/views/generic_resources/resources/new.html.erb +1 -3
- data/config/locales/generic_resources.de.yml +0 -0
- data/config/routes.rb +0 -0
- data/lib/generic_resource.rb +3 -2
- data/lib/generic_resources/acts_as_generic_resource.rb +23 -12
- data/lib/generic_resources/engine.rb +0 -0
- data/lib/generic_resources.rb +0 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ed552a3f0febc777983aea38b7cf711769bf4af6ef392efa5b833f98f19a8888
|
4
|
+
data.tar.gz: 9f16feb1bb26233ab89334375f8a81d2ea929e2a69f241d35506abadff913209
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 752101b594364f1b58aa58c066886348ceb64448058bc16a859e9358206e921b10b5168904c97623163c6132b7002e914c3eae3d87a9462ff8d46646001558b0
|
7
|
+
data.tar.gz: e4fd97ddf30f90b1eb5a2ff7069078f7ccb43cd1504f56f56148cbf89c86e50543cef120c0f324ab9b8642656ea752932f33573f5ebd8aefcfc5ee8bd735ca0f
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class GenericResources::ResourcesController < GenericResources.configuration.parent_controller.to_s.constantize
|
2
2
|
|
3
|
-
|
3
|
+
before_action :assign_resource, except: [:all]
|
4
4
|
|
5
5
|
def all
|
6
6
|
|
@@ -43,6 +43,13 @@ class GenericResources::ResourcesController < GenericResources.configuration.par
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def destroy
|
46
|
+
if GenericResource.resources[params[:resource_name]][:resource_deleteable]
|
47
|
+
@resource.destroy
|
48
|
+
flash[:notice] = I18n.t('generic_resources.controller.flash.notice.destroyed', resource_name: @resource_class.model_name.human)
|
49
|
+
else
|
50
|
+
flash[:notice] = I18n.t('generic_resources.controller.flash.error.not_destroyed', resource_name: @resource_class.model_name.human)
|
51
|
+
end
|
52
|
+
redirect_to_index
|
46
53
|
end
|
47
54
|
|
48
55
|
private
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<div class="spacer">
|
2
|
+
<%= render "generic_resources/resources/forms/#{params[:resource_name]}", f: f %>
|
3
|
+
</div>
|
4
|
+
|
5
|
+
<% if defined?(CaptainHooks) %>
|
6
|
+
<div class="spacer"><%= render_captain_hooks_for("generic_resource_form_#{@resource_class.model_name.singular}".to_sym, { f: f} ) %></div>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<%= f.submit t("generic_resources.forms.create_resource", resource_name: @resource_class.model_name.human) %>
|
File without changes
|
@@ -1,5 +1,3 @@
|
|
1
|
-
<%= form_for @resource, url: generic_resources.generic_resources_resource_path, html: { method: :patch} do |f| %>
|
2
|
-
<%= render "generic_resources/
|
3
|
-
<br />
|
4
|
-
<%= f.submit t("generic_resources.forms.save_resource", resource_name: @resource_class.model_name.human) %>
|
1
|
+
<%= form_for @resource, url: generic_resources.generic_resources_resource_path, html: { method: :patch, multipart: true} do |f| %>
|
2
|
+
<%= render "/generic_resources/form", f: f %>
|
5
3
|
<% end %>
|
File without changes
|
@@ -1,5 +1,3 @@
|
|
1
1
|
<%= form_for @resource, url: generic_resources.generic_resources_resources_path, html: { method: :post} do |f| %>
|
2
|
-
<%= render "generic_resources/
|
3
|
-
<br />
|
4
|
-
<%= f.submit t("generic_resources.forms.create_resource", resource_name: @resource_class.model_name.human) %>
|
2
|
+
<%= render "/generic_resources/form", f: f %>
|
5
3
|
<% end %>
|
File without changes
|
data/config/routes.rb
CHANGED
File without changes
|
data/lib/generic_resource.rb
CHANGED
@@ -2,12 +2,13 @@ module GenericResource
|
|
2
2
|
|
3
3
|
mattr_accessor :resources
|
4
4
|
|
5
|
-
def self.register_resource!(klass, permitted_attributes: [], overview_attributes: [])
|
5
|
+
def self.register_resource!(klass, permitted_attributes: [], overview_attributes: [], resource_deleteable: false)
|
6
6
|
@@resources ||= {}
|
7
7
|
@@resources[klass.name.underscore.gsub("/","_")] = {
|
8
8
|
class: klass,
|
9
9
|
permitted_attributes: permitted_attributes,
|
10
|
-
overview_attributes: overview_attributes
|
10
|
+
overview_attributes: overview_attributes,
|
11
|
+
resource_deleteable: resource_deleteable
|
11
12
|
}
|
12
13
|
end
|
13
14
|
|
@@ -8,21 +8,32 @@ module GenericResources
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
-
def acts_as_generic_resource(permitted_attributes: [], overview_attributes: [])
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def acts_as_generic_resource(permitted_attributes: [], overview_attributes: [], deleteable: false)
|
12
|
+
|
13
|
+
resource_deleteable = true if deleteable == true
|
14
|
+
begin
|
15
|
+
if !self.table_exists?
|
16
|
+
Rails.logger.warn "Try to add generic resource #{self.name} - table does not exist"
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
|
20
|
+
if permitted_attributes.empty?
|
21
|
+
permitted_attributes = (self.try(:column_names) || []) - ['id', 'created_at', 'updated_at']
|
22
|
+
end
|
23
|
+
|
24
|
+
if overview_attributes.empty?
|
25
|
+
overview_attributes = permitted_attributes
|
26
|
+
end
|
27
|
+
|
28
|
+
GenericResource.register_resource!(self,
|
29
|
+
permitted_attributes: permitted_attributes, overview_attributes: overview_attributes,
|
30
|
+
resource_deleteable: resource_deleteable
|
31
|
+
)
|
32
|
+
rescue ActiveRecord::NoDatabaseError => e
|
33
|
+
puts "SKIPPING acts_as_generic_resource on #{self.name} - NoDatabase"
|
15
34
|
end
|
16
35
|
|
17
|
-
if permitted_attributes.empty?
|
18
|
-
permitted_attributes = (self.try(:column_names) || []) - ['id', 'created_at', 'updated_at']
|
19
|
-
end
|
20
|
-
|
21
|
-
if overview_attributes.empty?
|
22
|
-
overview_attributes = permitted_attributes
|
23
|
-
end
|
24
36
|
|
25
|
-
GenericResource.register_resource!(self, permitted_attributes: permitted_attributes, overview_attributes: overview_attributes)
|
26
37
|
end
|
27
38
|
end
|
28
39
|
|
File without changes
|
data/lib/generic_resources.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: generic_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Eck
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- app/controllers/generic_resources/resources_controller.rb
|
63
|
+
- app/views/generic_resources/_form.html.erb
|
63
64
|
- app/views/generic_resources/resources/all.html.example.erb
|
64
65
|
- app/views/generic_resources/resources/edit.html.erb
|
65
66
|
- app/views/generic_resources/resources/index.example.html.erb
|
@@ -74,7 +75,7 @@ homepage: https://github.com/florianeck/generic_resources
|
|
74
75
|
licenses:
|
75
76
|
- MIT
|
76
77
|
metadata: {}
|
77
|
-
post_install_message:
|
78
|
+
post_install_message:
|
78
79
|
rdoc_options: []
|
79
80
|
require_paths:
|
80
81
|
- lib
|
@@ -89,9 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
90
|
- !ruby/object:Gem::Version
|
90
91
|
version: '0'
|
91
92
|
requirements: []
|
92
|
-
|
93
|
-
|
94
|
-
signing_key:
|
93
|
+
rubygems_version: 3.0.8
|
94
|
+
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: Easy CRUD Interface for Rails
|
97
97
|
test_files: []
|