generic_resources 0.1.3 → 0.1.9

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: abfad9c3605db6df5852b517a3cad3d0e04e74f9
4
- data.tar.gz: 61f2d05e6e14eba7b16051e776834bec3521241f
2
+ SHA256:
3
+ metadata.gz: ed552a3f0febc777983aea38b7cf711769bf4af6ef392efa5b833f98f19a8888
4
+ data.tar.gz: 9f16feb1bb26233ab89334375f8a81d2ea929e2a69f241d35506abadff913209
5
5
  SHA512:
6
- metadata.gz: f32a3124adc5da16ec6b47a14baff3f97d4203afff83527a07b3f3f511a31bc84a61c6b5b3dbcdcc4c988030cd3f65a6729e5a7ba6bbeb2b9ede1f6d95bf7033
7
- data.tar.gz: fd48459591ac491543e2b1450d696d9bd07ea2260f899ab06bc7d1511ee8067f59ccc2822d5b310bb46c771c955cf3eca44c0e52a817982fe395ce7a107f80aa
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
- before_filter :assign_resource, except: [:all]
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) %>
@@ -1,5 +1,3 @@
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 %>
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 %>
@@ -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 %>
File without changes
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.3
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: 2018-01-09 00:00:00.000000000 Z
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
- 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: []