effective_resources 0.8.13 → 0.8.14
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68074e96512d111e7b55e78fd29b1b15496f4363
|
4
|
+
data.tar.gz: df35b07a9314f9f181b3505e808b1693d4d9756c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba76ceb463231bbf9c61e844ddc39dd60cd010c18b61bc7d121ed890ead8bc97e15aafacd96a50ba208c67211578b20a0ac30a82769e2c679de263fe8d3f5aec
|
7
|
+
data.tar.gz: 44235f52f3fdfcf346b4fec727439b032ba51e82928bcf21ab43f554161d59b95d585359490c20da636cbbd41cafaf9cdd376b901abcc422f9f00098daecab17
|
@@ -82,11 +82,12 @@ module Effective
|
|
82
82
|
|
83
83
|
# page_title 'My Title', only: [:new]
|
84
84
|
def page_title(label = nil, opts = {}, &block)
|
85
|
+
opts = label if label.kind_of?(Hash)
|
85
86
|
raise 'expected a label or block' unless (label || block_given?)
|
86
87
|
|
87
88
|
instance_exec do
|
88
89
|
before_action(opts) do
|
89
|
-
@page_title ||= (block_given? ? instance_exec(&block) : label)
|
90
|
+
@page_title ||= (block_given? ? instance_exec(&block) : label).to_s
|
90
91
|
end
|
91
92
|
end
|
92
93
|
end
|
@@ -328,13 +329,13 @@ module Effective
|
|
328
329
|
if save_resource(resource, action, (send(resource_params_method_name) rescue {}))
|
329
330
|
format.html do
|
330
331
|
flash[:success] ||= resource_flash(:success, resource, action)
|
331
|
-
redirect_to(resource_redirect_path)
|
332
|
+
redirect_to(resource_redirect_path(action))
|
332
333
|
end
|
333
334
|
|
334
335
|
format.js do
|
335
336
|
if specific_redirect_path?(action)
|
336
337
|
flash[:success] ||= resource_flash(:success, resource, action)
|
337
|
-
redirect_to(resource_redirect_path)
|
338
|
+
redirect_to(resource_redirect_path(action))
|
338
339
|
else
|
339
340
|
flash.now[:success] ||= resource_flash(:success, resource, action)
|
340
341
|
reload_resource
|
@@ -358,7 +359,7 @@ module Effective
|
|
358
359
|
else
|
359
360
|
@page_title ||= resource.to_s
|
360
361
|
flash[:danger] = flash.now[:danger]
|
361
|
-
redirect_to(referer_redirect_path || resource_redirect_path)
|
362
|
+
redirect_to(referer_redirect_path || resource_redirect_path(action))
|
362
363
|
end
|
363
364
|
end
|
364
365
|
|
@@ -439,7 +440,8 @@ module Effective
|
|
439
440
|
end
|
440
441
|
|
441
442
|
def resource_flash(status, resource, action)
|
442
|
-
|
443
|
+
submit = commit_action(action)
|
444
|
+
message = submit[status].respond_to?(:call) ? instance_exec(&submit[status]) : submit[status]
|
443
445
|
return message if message.present?
|
444
446
|
|
445
447
|
message || case status
|
@@ -450,8 +452,9 @@ module Effective
|
|
450
452
|
end
|
451
453
|
end
|
452
454
|
|
453
|
-
def resource_redirect_path
|
454
|
-
|
455
|
+
def resource_redirect_path(action = nil)
|
456
|
+
submit = commit_action(action)
|
457
|
+
redirect = submit[:redirect].respond_to?(:call) ? instance_exec(&submit[:redirect]) : submit[:redirect]
|
455
458
|
|
456
459
|
commit_action_redirect = case redirect
|
457
460
|
when :index ; resource_index_path
|
@@ -461,7 +464,7 @@ module Effective
|
|
461
464
|
when :duplicate ; resource_duplicate_path
|
462
465
|
when :back ; referer_redirect_path
|
463
466
|
when :save ; [resource_edit_path, resource_show_path].compact.first
|
464
|
-
when Symbol ; resource_action_path(
|
467
|
+
when Symbol ; resource_action_path(submit[:action])
|
465
468
|
when String ; redirect
|
466
469
|
else ; nil
|
467
470
|
end
|
@@ -562,20 +565,17 @@ module Effective
|
|
562
565
|
(action.to_s + (action.to_s.end_with?('e') ? 'd' : 'ed'))
|
563
566
|
end
|
564
567
|
|
565
|
-
|
568
|
+
# Based on the incoming params[:commit] or passed action
|
569
|
+
def commit_action(action = nil)
|
566
570
|
self.class.submits[params[:commit].to_s] ||
|
567
|
-
self.class.submits.find { |_, v| v[:action] == :save }&.last ||
|
568
|
-
{ action: :save }
|
569
|
-
end
|
570
|
-
|
571
|
-
def submit_action(action)
|
572
571
|
self.class.submits[action.to_s] ||
|
573
572
|
self.class.submits.find { |_, v| v[:action] == action }&.last ||
|
574
|
-
{ action:
|
573
|
+
self.class.submits.find { |_, v| v[:action] == :save }&.last ||
|
574
|
+
{ action: (action || :save) }
|
575
575
|
end
|
576
576
|
|
577
577
|
def specific_redirect_path?(action = nil)
|
578
|
-
submit =
|
578
|
+
submit = commit_action(action)
|
579
579
|
(submit[:redirect].respond_to?(:call) ? instance_exec(&submit[:redirect]) : submit[:redirect]).present?
|
580
580
|
end
|
581
581
|
|
@@ -6,10 +6,11 @@ module Effective
|
|
6
6
|
def flash_success(resource, action = nil, name: nil)
|
7
7
|
raise 'expected an ActiveRecord resource' unless (name || resource.class.respond_to?(:model_name))
|
8
8
|
|
9
|
-
action ||= :save
|
10
9
|
name ||= resource.class.model_name.human
|
11
10
|
|
12
|
-
|
11
|
+
action = (action || :save).to_s.gsub('_', ' ')
|
12
|
+
|
13
|
+
"#{name.to_s.titleize} was successfully #{action}#{(action == 'submit' ? 't' : '')}#{(action.end_with?('e') ? 'd' : 'ed')}"
|
13
14
|
end
|
14
15
|
|
15
16
|
# flash.now[:danger] = flash_danger(@post)
|
@@ -17,6 +18,7 @@ module Effective
|
|
17
18
|
raise 'expected an ActiveRecord resource' unless resource.respond_to?(:errors) && (name || resource.class.respond_to?(:model_name))
|
18
19
|
|
19
20
|
action ||= resource.respond_to?(:new_record?) ? (resource.new_record? ? :create : :update) : :save
|
21
|
+
action = action.to_s.gsub('_', ' ')
|
20
22
|
name ||= resource.class.model_name.human
|
21
23
|
messages = flash_errors(resource, e: e)
|
22
24
|
|