effective_resources 1.0.19 → 1.1.0
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 +4 -4
- data/app/controllers/concerns/effective/crud_controller.rb +8 -2
- data/app/controllers/concerns/effective/crud_controller/permitted_params.rb +11 -0
- data/app/controllers/concerns/effective/crud_controller/respond.rb +19 -5
- data/app/models/effective/resources/klass.rb +4 -0
- data/lib/effective_resources/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 962a290756ff82a2d328b486f9d381cb7f97568b
|
4
|
+
data.tar.gz: 3059d2ba54c29292b5b704ca2fde4b40feaf3969
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c87bbabac3cc1e732d1e673a0462068ba9b13623c5e4ed3418c5b51443684063ac8217c2e15238136c0d2d7c6c2a132319b16ac9a7e4eec9112269b0a0a36b59
|
7
|
+
data.tar.gz: 4a1cf91f0d0cf9d593658df108f80831f4fee7ff5d30af83a113f4b637dd779879b81add4869525cfed905822db94d666e4067bf56d95837fab5e9cb8d643a20
|
@@ -37,6 +37,10 @@ module Effective
|
|
37
37
|
if effective_resource.model.present?
|
38
38
|
define_method(:effective_resource_permitted_params) { resource_permitted_params } # save.rb
|
39
39
|
end
|
40
|
+
|
41
|
+
if effective_resource.active_model?
|
42
|
+
define_method(:effective_resource_permitted_params) { resource_active_model_permitted_params } # save.rb
|
43
|
+
end
|
40
44
|
end
|
41
45
|
|
42
46
|
end
|
@@ -86,12 +90,14 @@ module Effective
|
|
86
90
|
when Symbol
|
87
91
|
effective_resource.klass.send(@_effective_resource_scope)
|
88
92
|
when nil
|
89
|
-
effective_resource.klass.all
|
93
|
+
effective_resource.klass.respond_to?(:all) ? effective_resource.klass.all : effective_resource.klass
|
90
94
|
else
|
91
95
|
raise "expected resource_scope method to return an ActiveRecord::Relation or Hash"
|
92
96
|
end
|
93
97
|
|
94
|
-
|
98
|
+
unless relation.kind_of?(ActiveRecord::Relation) || effective_resource.active_model?
|
99
|
+
raise("unable to build resource_scope for #{effective_resource.klass || 'unknown klass'}.")
|
100
|
+
end
|
95
101
|
|
96
102
|
relation
|
97
103
|
)
|
@@ -19,6 +19,17 @@ module Effective
|
|
19
19
|
params.require(effective_resource.name).permit(*permitted_params)
|
20
20
|
end
|
21
21
|
|
22
|
+
# If the resource is ActiveModel, just permit all
|
23
|
+
# This can still be overridden by a controller
|
24
|
+
def resource_active_model_permitted_params
|
25
|
+
if Rails.env.development?
|
26
|
+
Rails.logger.info "Effective::CrudController#resource_permitted_params:"
|
27
|
+
Rails.logger.info "params.require(:#{effective_resource.name}).permit!"
|
28
|
+
end
|
29
|
+
|
30
|
+
params.require(effective_resource.name).permit!
|
31
|
+
end
|
32
|
+
|
22
33
|
private
|
23
34
|
|
24
35
|
def permitted_params_for(resource, namespaces = [])
|
@@ -40,8 +40,16 @@ module Effective
|
|
40
40
|
flash.delete(:success)
|
41
41
|
flash.now[:danger] ||= resource_flash(:danger, resource, action)
|
42
42
|
|
43
|
+
redirect_flash if specific_redirect_path?(:error)
|
44
|
+
|
43
45
|
run_callbacks(:resource_render)
|
44
46
|
|
47
|
+
if specific_redirect_path?(:error)
|
48
|
+
format.html { redirect_to resource_redirect_path(:error) }
|
49
|
+
format.js { redirect_to resource_redirect_path(:error) }
|
50
|
+
return
|
51
|
+
end
|
52
|
+
|
45
53
|
# HTML responder
|
46
54
|
case action.to_sym
|
47
55
|
when :create
|
@@ -50,8 +58,7 @@ module Effective
|
|
50
58
|
format.html { render :edit }
|
51
59
|
when :destroy
|
52
60
|
format.html do
|
53
|
-
|
54
|
-
flash[:danger] = resource_flash(:danger, resource, action)
|
61
|
+
redirect_flash
|
55
62
|
redirect_to(resource_redirect_path(action))
|
56
63
|
end
|
57
64
|
else # member action
|
@@ -70,9 +77,7 @@ module Effective
|
|
70
77
|
render :show
|
71
78
|
else
|
72
79
|
@page_title ||= resource.to_s
|
73
|
-
|
74
|
-
flash[:danger] = resource_flash(:danger, resource, action)
|
75
|
-
|
80
|
+
redirect_flash
|
76
81
|
redirect_to(referer_redirect_path || resource_redirect_path(action))
|
77
82
|
end
|
78
83
|
end
|
@@ -82,7 +87,16 @@ module Effective
|
|
82
87
|
view = lookup_context.template_exists?(action, _prefixes) ? action : :member_action
|
83
88
|
render(view, locals: { action: action }) # action.js.erb
|
84
89
|
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def redirect_flash
|
95
|
+
return unless flash.now[:danger].present?
|
85
96
|
|
97
|
+
danger = flash.now[:danger]
|
98
|
+
flash.now[:danger] = nil
|
99
|
+
flash[:danger] ||= danger
|
86
100
|
end
|
87
101
|
|
88
102
|
end
|