generic_resources 0.1.4 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 75fb02a03d4f428710356dedbc0c1c96ae1f69f6
4
- data.tar.gz: 1c90d82ee9493aaffc309e27f83ec6f0437c305b
2
+ SHA256:
3
+ metadata.gz: 7f88ed11f62a29483b17c6fd68a207df9f2eb4812079052360eddbea90b54052
4
+ data.tar.gz: 3afb8f0ff81d5be54152b59f10f7e6ca7d56c75a619d4940748e5a8b1fa1b6cc
5
5
  SHA512:
6
- metadata.gz: 47c273af29f637cdbe723b092420996bab0672cf43d2e0425efd1074c9395907af117c7c985a159599263b2ad328737a5dc350c6a49d63aa5e3d939774f8e9c2
7
- data.tar.gz: e5e106baca61fa629f22ad6cd53216aa3356b8ee7a13296c8b337d000539946000eaf2d81215032ebb64332c4f8b96634fd62ed6f351db40a4585f9ccc60e769
6
+ metadata.gz: 5a49428c0e19c582f8241c3c68b2a586dc5dd2d3a2d89a2d87220481c38dcec5c139581b7d10e003f6005e01fa678f465b8b57e6ba9ad4a3848bcfbcf7511ae6
7
+ data.tar.gz: bb4ff85724bb8478ced9d60f91146d47128cc40e5b60786bdcd64d0fb4b21796efa896b687bb3d5b6f64bf1f5bc7beb802a0aa750accda2121281157b91559f5
@@ -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
@@ -55,10 +62,10 @@ class GenericResources::ResourcesController < GenericResources.configuration.par
55
62
  def assign_resource
56
63
  if params[:resource_name].nil?
57
64
  flash[:error] = I18n.t('generic_resources.controller.flash.error.resource_type_missing')
58
- redirect_to :back
65
+ redirect_to action: :index
59
66
  elsif GenericResource.resources[params[:resource_name]].nil?
60
67
  flash[:error] = I18n.t('generic_resources.controller.flash.error.resource_type_not_found', resource_name: params[:resource_name])
61
- redirect_to :back
68
+ redirect_to action: :index
62
69
  else
63
70
  @resource_class = GenericResource.resources[params[:resource_name]][:class]
64
71
 
@@ -0,0 +1,10 @@
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.save_resource", resource_name: @resource_class.model_name.human) %>
10
+
@@ -1,5 +1,8 @@
1
- <%= form_for @resource, url: generic_resources.generic_resources_resource_path, html: { method: :patch} do |f| %>
2
- <%= render "generic_resources/resources/forms/#{params[:resource_name]}", f: f %>
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 %>
3
+ <% end %>
4
+
5
+ <% if GenericResource.resources[params[:resource_name]][:resource_deleteable] %>
3
6
  <br />
4
- <%= f.submit t("generic_resources.forms.save_resource", resource_name: @resource_class.model_name.human) %>
7
+ <%= link_to t("generic_resources.forms.delete_resource"), generic_resources.generic_resources_resource_path, method: :delete, data: { confirm: t("generic_resources.forms.delete_confirm") } %>
5
8
  <% end %>
@@ -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/resources/forms/#{params[:resource_name]}", f: f %>
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 %>
@@ -14,6 +14,9 @@ de:
14
14
  notice:
15
15
  created: "%{resource_name} wurde erfolgreich angelegt"
16
16
  updated: "%{resource_name} wurde erfolgreich aktualisiert"
17
+ destroyed: "%{resource_name} wurde erfolgreich gelöscht"
17
18
  forms:
18
19
  save_resource: "%{resource_name} speichern"
19
20
  create_resource: "%{resource_name} anlegen"
21
+ delete_resource: "Eintrag löschen"
22
+ delete_confirm: "Sicher? Das löschen kann nicht rückgängig gemacht werden"
data/config/routes.rb CHANGED
File without changes
@@ -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
- if !self.table_exists?
13
- Rails.logger.warn "Try to add generic resource #{self.name} - table does not exist"
14
- return false
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
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
4
+ version: 0.1.10
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: 2018-02-16 00:00:00.000000000 Z
11
+ date: 2022-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -53,13 +53,14 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Use just one Controller to CRUD all your resources instead of having
56
- lots of of scaffold controllers
56
+ lots of scaffold controllers
57
57
  email: florian.eck@el-digital.de
58
58
  executables: []
59
59
  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
- rubyforge_project:
93
- rubygems_version: 2.6.12
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: []