effective_resources 1.0.12 → 1.0.13

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
2
  SHA1:
3
- metadata.gz: 60db7705f1fb377c10d9bd981079ce1eea482636
4
- data.tar.gz: f05b029bd2600fddbb9871b248d94b704617a35d
3
+ metadata.gz: 998ed6153bddd85970840b07e11a165512fcce3e
4
+ data.tar.gz: 04d9581c21c2ff8499abf8bfc0995956b476eb96
5
5
  SHA512:
6
- metadata.gz: 5acca8d4926d6cec59a2cffbbe521fb5abb873cb7e2559952ef9964d6832f9990984ade64711768d0ff412b6b61a2b8a3fbf5e149f9a19f7d32efaa90a022886
7
- data.tar.gz: 92d3bf93a553331231c93c6f40d54dad32132d642fa0c62ab3421a382917c7e784c1233edea43a9651a81c9db190c587715266efcf12ff1de388feac7d322eb2
6
+ metadata.gz: 484de341ce813ef6fe402dd59b33ad0a5e5c8d8dfab95fcccb1230359a60ad1a888ba75de70951138e5172087dc49f3a531af0742dd8ba19338f47ad6915f871
7
+ data.tar.gz: 80059d4e5ce2b3fe4625ecfbfe6bda6cb6b4c5c924f37c2ba27861955cf6433f51d77dce5534814448cb940878a5b4af3994a3000340b6d133f6c515a45327d5
@@ -147,13 +147,7 @@ module Effective
147
147
  if save_resource(resource, action)
148
148
  respond_with_success(format, resource, action)
149
149
  else
150
- flash.delete(:success)
151
- request.format = :html # Don't run destroy.js.erb
152
-
153
- format.html do
154
- flash[:danger] = (flash.now[:danger].presence || resource_flash(:danger, resource, action))
155
- redirect_to(resource_redirect_path(action))
156
- end
150
+ respond_with_error(format, resource, action)
157
151
  end
158
152
  end
159
153
  end
@@ -175,31 +169,9 @@ module Effective
175
169
 
176
170
  respond_to do |format|
177
171
  if save_resource(resource, action)
178
- respond_with_success(format, resource, action) || render_member_action(action)
172
+ respond_with_success(format, resource, action)
179
173
  else
180
- flash.delete(:success)
181
- flash.now[:danger] ||= resource_flash(:danger, resource, action)
182
-
183
- run_callbacks(:resource_render)
184
-
185
- format.html do
186
- if resource_edit_path && (referer_redirect_path || '').end_with?(resource_edit_path)
187
- @page_title ||= "Edit #{resource}"
188
- render :edit
189
- elsif resource_new_path && (referer_redirect_path || '').end_with?(resource_new_path)
190
- @page_title ||= "New #{resource_name.titleize}"
191
- render :new
192
- elsif resource_show_path && (referer_redirect_path || '').end_with?(resource_show_path)
193
- @page_title ||= resource_name.titleize
194
- render :show
195
- else
196
- @page_title ||= resource.to_s
197
- flash[:danger] = flash.now[:danger]
198
- redirect_to(referer_redirect_path || resource_redirect_path(action))
199
- end
200
- end
201
-
202
- format.js { render_member_action(action) }
174
+ respond_with_error(format, resource, action)
203
175
  end
204
176
  end
205
177
  end
@@ -246,13 +218,5 @@ module Effective
246
218
  end
247
219
  end
248
220
 
249
- private
250
-
251
- # Which member javascript view to render: #{action}.js or effective_resources member_action.js
252
- def render_member_action(action)
253
- view = lookup_context.template_exists?(action, _prefixes) ? action : :member_action
254
- render(view, locals: { action: action })
255
- end
256
-
257
221
  end
258
222
  end
@@ -2,7 +2,7 @@ module Effective
2
2
  module CrudController
3
3
  module Respond
4
4
  def respond_with_success(format, resource, action)
5
- if specific_redirect_path?
5
+ if specific_redirect_path?(action)
6
6
  format.html do
7
7
  flash[:success] ||= resource_flash(:success, resource, action)
8
8
  redirect_to(resource_redirect_path(action))
@@ -12,12 +12,7 @@ module Effective
12
12
  flash[:success] ||= resource_flash(:success, resource, action)
13
13
  redirect_to(resource_redirect_path(action))
14
14
  end
15
-
16
- return true
17
- end
18
-
19
- # Render template if it exists
20
- if lookup_context.template_exists?(action, _prefixes)
15
+ elsif lookup_context.template_exists?(action, _prefixes)
21
16
  format.html do
22
17
  flash.now[:success] ||= resource_flash(:success, resource, action)
23
18
  # action.html.haml
@@ -28,22 +23,17 @@ module Effective
28
23
  reload_resource
29
24
  # action.js.erb
30
25
  end
26
+ else # Default
27
+ format.html do
28
+ flash[:success] ||= resource_flash(:success, resource, action)
29
+ redirect_to(resource_redirect_path(action))
30
+ end
31
31
 
32
- return false
33
- end
34
-
35
- # Default
36
- format.html do
37
- flash[:success] ||= resource_flash(:success, resource, action)
38
- redirect_to(resource_redirect_path(action))
39
- end
40
-
41
- format.js do
42
- flash[:success] ||= resource_flash(:success, resource, action)
43
- redirect_to(resource_redirect_path(action))
32
+ format.js do
33
+ flash.now[:success] ||= resource_flash(:success, resource, action)
34
+ render(:member_action, locals: { action: action })
35
+ end
44
36
  end
45
-
46
- true
47
37
  end
48
38
 
49
39
  def respond_with_error(format, resource, action)
@@ -57,11 +47,52 @@ module Effective
57
47
  format.html { render :new }
58
48
  when 'update'
59
49
  format.html { render :edit }
60
- else
61
- format.html { render action }
50
+ when 'destroy'
51
+ # We always need to redirect here
52
+ flash[:danger] = flash.now.delete(:danger)
53
+
54
+ format.html { redirect_to(resource_redirect_path(action)) }
55
+ format.js { redirect_to(resource_redirect_path(action)) }
56
+ else # member_action
57
+ format.html do
58
+ if lookup_context.template_exists?(action, _prefixes)
59
+ @page_title ||= "#{action.to_s.titleize} #{resource}"
60
+ render(action, locals: { action: action })
61
+ elsif resource_edit_path && (referer_redirect_path || '').end_with?(resource_edit_path)
62
+ @page_title ||= "Edit #{resource}"
63
+ render :edit
64
+ elsif resource_new_path && (referer_redirect_path || '').end_with?(resource_new_path)
65
+ @page_title ||= "New #{resource_name.titleize}"
66
+ render :new
67
+ elsif resource_show_path && (referer_redirect_path || '').end_with?(resource_show_path)
68
+ @page_title ||= resource_name.titleize
69
+ render :show
70
+ else
71
+ @page_title ||= resource.to_s
72
+ flash[:danger] = flash.now.delete(:danger)
73
+ redirect_to(referer_redirect_path || resource_redirect_path(action))
74
+ end
75
+ end
62
76
  end
63
77
 
64
- format.js {}
78
+ format.js do
79
+ view = lookup_context.template_exists?(action, _prefixes) ? action : :member_action
80
+ render(view, locals: { action: action })
81
+ end
82
+ end
83
+
84
+ # For destroy.js
85
+ def respond_with_error_and_redirect(format, resource, action)
86
+ flash.delete(:success)
87
+ flash[:danger] ||= resource_flash(:danger, resource, action)
88
+
89
+ format.html do
90
+ redirect_to(resource_redirect_path(action))
91
+ end
92
+
93
+ format.js do
94
+ redirect_to(resource_redirect_path(action))
95
+ end
65
96
  end
66
97
 
67
98
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.0.12'.freeze
2
+ VERSION = '1.0.13'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-19 00:00:00.000000000 Z
11
+ date: 2018-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails