effective_resources 1.2.14 → 1.2.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -15
- data/app/controllers/concerns/effective/crud_controller/actions.rb +16 -24
- data/app/controllers/concerns/effective/crud_controller/respond.rb +69 -61
- data/app/controllers/concerns/effective/crud_controller/save.rb +1 -2
- data/lib/effective_resources/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9c1374e91be1d5cc6a59a84d3bf3101b6f070e3
|
4
|
+
data.tar.gz: 54937ae6e523329f6078a89bd9f013978e0cbfb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 105eef30f447c6623b55b0073a3456ad89fad27ab8e0db2589e8402b8b7a491d31f319fc59554b4a8c44e0486ac26112eb54903014c29ce512e5be84ae84c5f3
|
7
|
+
data.tar.gz: 1e1d91e424de80e48c73b630813f9b9b3cf4704b1d4ff60d847672608331de5ae1427d270e93cf202654111125791d8a894f8a4cfe8f565e13f38c3d1d0341d1
|
data/README.md
CHANGED
@@ -148,7 +148,7 @@ class PostsController < ApplicationController
|
|
148
148
|
# Sets the @page_title in a before_filter
|
149
149
|
page_title 'My Posts', only: [:index]
|
150
150
|
|
151
|
-
# Callbacks: before_save, after_save,
|
151
|
+
# Callbacks: before_render, before_save, after_save, after_error, after_commit
|
152
152
|
before_render(only: :new) do
|
153
153
|
resource.client = current_user.clients.first
|
154
154
|
end
|
@@ -166,20 +166,6 @@ class PostsController < ApplicationController
|
|
166
166
|
Post.active.where(user: current_user)
|
167
167
|
end
|
168
168
|
|
169
|
-
# The following methods are discovered from the routes.rb and defined automatically.
|
170
|
-
# But you could also define them like this if you wanted.
|
171
|
-
|
172
|
-
# When GET request, will render the approve page
|
173
|
-
# When POST|PATCH|PUT request, will call @post.approve! and do the right thing
|
174
|
-
member_action :approve
|
175
|
-
|
176
|
-
# When GET request, will render an index page scoped to this method (if it's a scope on the model i.e. Post.approved)
|
177
|
-
collection_action :approved
|
178
|
-
|
179
|
-
# When POST|PATCH|PUT request, will call @post.approve! on each post as per params[:ids]
|
180
|
-
# Created with effective_datatables bulk actions in mind
|
181
|
-
collection_action :bulk_approve
|
182
|
-
|
183
169
|
protected
|
184
170
|
|
185
171
|
# The post_params are discovered from the model effective_resource do ... end block.
|
@@ -69,12 +69,10 @@ module Effective
|
|
69
69
|
EffectiveResources.authorize!(self, action, resource)
|
70
70
|
@page_title ||= "New #{resource_name.titleize}"
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
respond_with_error(format, resource, action)
|
77
|
-
end
|
72
|
+
if save_resource(resource, action)
|
73
|
+
respond_with_success(resource, action)
|
74
|
+
else
|
75
|
+
respond_with_error(resource, action)
|
78
76
|
end
|
79
77
|
end
|
80
78
|
|
@@ -123,12 +121,10 @@ module Effective
|
|
123
121
|
|
124
122
|
resource.assign_attributes(send(resource_params_method_name))
|
125
123
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
respond_with_error(format, resource, action)
|
131
|
-
end
|
124
|
+
if save_resource(resource, action)
|
125
|
+
respond_with_success(resource, action)
|
126
|
+
else
|
127
|
+
respond_with_error(resource, action)
|
132
128
|
end
|
133
129
|
end
|
134
130
|
|
@@ -145,12 +141,10 @@ module Effective
|
|
145
141
|
EffectiveResources.authorize!(self, action, resource)
|
146
142
|
@page_title ||= "Destroy #{resource}"
|
147
143
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
respond_with_error(format, resource, action)
|
153
|
-
end
|
144
|
+
if save_resource(resource, action)
|
145
|
+
respond_with_success(resource, action)
|
146
|
+
else
|
147
|
+
respond_with_error(resource, action)
|
154
148
|
end
|
155
149
|
end
|
156
150
|
|
@@ -176,12 +170,10 @@ module Effective
|
|
176
170
|
to_assign = (send(resource_params_method_name) rescue {})
|
177
171
|
resource.assign_attributes(to_assign) if to_assign.present? && to_assign.permitted?
|
178
172
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
respond_with_error(format, resource, action)
|
184
|
-
end
|
173
|
+
if save_resource(resource, action)
|
174
|
+
respond_with_success(resource, action)
|
175
|
+
else
|
176
|
+
respond_with_error(resource, action)
|
185
177
|
end
|
186
178
|
end
|
187
179
|
|
@@ -1,86 +1,94 @@
|
|
1
1
|
module Effective
|
2
2
|
module CrudController
|
3
3
|
module Respond
|
4
|
-
def respond_with_success(
|
4
|
+
def respond_with_success(resource, action)
|
5
|
+
return if response.body.present?
|
6
|
+
|
5
7
|
if specific_redirect_path?(action)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
respond_to do |format|
|
9
|
+
format.html do
|
10
|
+
flash[:success] ||= resource_flash(:success, resource, action)
|
11
|
+
redirect_to(resource_redirect_path(action))
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
format.js do
|
15
|
+
flash[:success] ||= resource_flash(:success, resource, action)
|
16
|
+
redirect_to(resource_redirect_path(action))
|
17
|
+
end
|
14
18
|
end
|
15
19
|
elsif template_present?(action)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
respond_to do |format|
|
21
|
+
format.html do
|
22
|
+
flash.now[:success] ||= resource_flash(:success, resource, action)
|
23
|
+
render(action) # action.html.haml
|
24
|
+
end
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
format.js do
|
27
|
+
flash.now[:success] ||= resource_flash(:success, resource, action)
|
28
|
+
#reload_resource unless action == :destroy # Removed.
|
29
|
+
render(action) # action.js.erb
|
30
|
+
end
|
25
31
|
end
|
26
|
-
elsif response_body.present? # We might have done something weird like send_data in an after_save
|
27
|
-
format.html { flash.now[:success] ||= resource_flash(:success, resource, action) }
|
28
|
-
format.js { flash.now[:success] ||= resource_flash(:success, resource, action) }
|
29
32
|
else # Default
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
respond_to do |format|
|
34
|
+
format.html do
|
35
|
+
flash[:success] ||= resource_flash(:success, resource, action)
|
36
|
+
redirect_to(resource_redirect_path(action))
|
37
|
+
end
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
|
39
|
+
format.js do
|
40
|
+
flash.now[:success] ||= resource_flash(:success, resource, action)
|
41
|
+
render(:member_action, locals: { action: action })
|
42
|
+
end
|
38
43
|
end
|
39
44
|
end
|
40
45
|
end
|
41
46
|
|
42
|
-
def respond_with_error(
|
47
|
+
def respond_with_error(resource, action)
|
48
|
+
return if response.body.present?
|
49
|
+
|
43
50
|
flash.delete(:success)
|
44
51
|
flash.now[:danger] ||= resource_flash(:danger, resource, action)
|
45
52
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
when :destroy
|
55
|
-
format.html do
|
56
|
-
redirect_flash
|
57
|
-
redirect_to(resource_redirect_path(action))
|
58
|
-
end
|
59
|
-
else # member action
|
60
|
-
format.html do
|
61
|
-
if resource_edit_path && referer_redirect_path.to_s.end_with?(resource_edit_path)
|
62
|
-
@page_title ||= "Edit #{resource}"
|
63
|
-
render :edit
|
64
|
-
elsif resource_new_path && referer_redirect_path.to_s.end_with?(resource_new_path)
|
65
|
-
@page_title ||= "New #{resource_name.titleize}"
|
66
|
-
render :new
|
67
|
-
elsif resource_action_path(action) && referer_redirect_path.to_s.end_with?(resource_action_path(action)) && template_present?(action)
|
68
|
-
@page_title ||= "#{action.to_s.titleize} #{resource}"
|
69
|
-
render(action, locals: { action: action })
|
70
|
-
elsif resource_show_path && referer_redirect_path.to_s.end_with?(resource_show_path)
|
71
|
-
@page_title ||= resource_name.titleize
|
72
|
-
render :show
|
73
|
-
else
|
74
|
-
@page_title ||= resource.to_s
|
53
|
+
respond_to do |format|
|
54
|
+
case action.to_sym
|
55
|
+
when :create
|
56
|
+
format.html { render :new }
|
57
|
+
when :update
|
58
|
+
format.html { render :edit }
|
59
|
+
when :destroy
|
60
|
+
format.html do
|
75
61
|
redirect_flash
|
76
|
-
redirect_to(
|
62
|
+
redirect_to(resource_redirect_path(action))
|
63
|
+
end
|
64
|
+
else # member action
|
65
|
+
from_path = referer_redirect_path.to_s
|
66
|
+
|
67
|
+
format.html do
|
68
|
+
if resource_edit_path && from_path.end_with?(resource_edit_path)
|
69
|
+
@page_title ||= "Edit #{resource}"
|
70
|
+
render :edit
|
71
|
+
elsif resource_new_path && from_path.end_with?(resource_new_path)
|
72
|
+
@page_title ||= "New #{resource_name.titleize}"
|
73
|
+
render :new
|
74
|
+
elsif resource_action_path(action) && from_path.end_with?(resource_action_path(action)) && template_present?(action)
|
75
|
+
@page_title ||= "#{action.to_s.titleize} #{resource}"
|
76
|
+
render(action, locals: { action: action })
|
77
|
+
elsif resource_show_path && from_path.end_with?(resource_show_path)
|
78
|
+
@page_title ||= resource_name.titleize
|
79
|
+
render :show
|
80
|
+
else
|
81
|
+
@page_title ||= resource.to_s
|
82
|
+
redirect_flash
|
83
|
+
redirect_to(from_path.presence || resource_redirect_path(action))
|
84
|
+
end
|
77
85
|
end
|
78
86
|
end
|
79
|
-
end
|
80
87
|
|
81
|
-
|
82
|
-
|
83
|
-
|
88
|
+
format.js do
|
89
|
+
view = template_present?(action) ? action : :member_action
|
90
|
+
render(view, locals: { action: action }) # action.js.erb
|
91
|
+
end
|
84
92
|
end
|
85
93
|
end
|
86
94
|
|
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.2.
|
4
|
+
version: 1.2.15
|
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: 2019-05-
|
11
|
+
date: 2019-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|