effective_resources 0.7.8 → 0.7.9
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/README.md +7 -1
- data/app/controllers/concerns/effective/crud_controller.rb +30 -0
- data/lib/effective_resources/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 022dfa4ea62f6a71b19192016d4a3108f657bda0
|
4
|
+
data.tar.gz: 2c0d60521353a87ca54acde430540636742adbd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f10e53623093ce79fe6b8a22aa10087aeed62014eb672338741d1277681c627cc7d1b5129c32cc1b0a1fa44332853ad9c2b02711d76801a130e85bbf3b356b71
|
7
|
+
data.tar.gz: cc17e8e6b4f1af4a4c1af4acdaaba2a47e4e9055ddee77975a05f878552410369ded8c65bedf01f1f9c0baa8f0cce4a069257554c0c0c8b254c7f93f863c010f
|
data/README.md
CHANGED
@@ -58,7 +58,13 @@ class PostsController < ApplicationController
|
|
58
58
|
|
59
59
|
# The permitted parameters for this post. Other recognized method names are posts_params and permitted_params
|
60
60
|
def post_params
|
61
|
-
params.require(:post).permit(:id, :title, :body)
|
61
|
+
params.require(:post).permit(:id, :author_id, :category, :title, :body)
|
62
|
+
end
|
63
|
+
|
64
|
+
# On #create or #update, if you click 'Add New', the new resource form will be rendered with these attributes preopulated
|
65
|
+
# Makes it super quick to Add New items if only one or two of the fields are changing.
|
66
|
+
def add_new_post_params
|
67
|
+
permitted_params.slice(:author_id, :category)
|
62
68
|
end
|
63
69
|
|
64
70
|
end
|
@@ -175,6 +175,11 @@ module Effective
|
|
175
175
|
resource.created_by ||= current_user if resource.respond_to?(:created_by=)
|
176
176
|
|
177
177
|
if save_resource(resource, action)
|
178
|
+
if add_new_resource_action?
|
179
|
+
render_add_new_resource! and return
|
180
|
+
end
|
181
|
+
|
182
|
+
# Normal redirect
|
178
183
|
flash[:success] ||= flash_success(resource, action)
|
179
184
|
redirect_to(resource_redirect_path)
|
180
185
|
else
|
@@ -213,6 +218,11 @@ module Effective
|
|
213
218
|
resource.assign_attributes(send(resource_params_method_name))
|
214
219
|
|
215
220
|
if save_resource(resource, action)
|
221
|
+
if add_new_resource_action?
|
222
|
+
render_add_new_resource! and return
|
223
|
+
end
|
224
|
+
|
225
|
+
# Normal save
|
216
226
|
flash[:success] ||= flash_success(resource, action)
|
217
227
|
redirect_to(resource_redirect_path)
|
218
228
|
else
|
@@ -362,6 +372,21 @@ module Effective
|
|
362
372
|
end.presence || root_path
|
363
373
|
end
|
364
374
|
|
375
|
+
def add_new_resource_action?
|
376
|
+
(add_new_resource_params_method_name.present? && resource_redirect_path == resource_new_path)
|
377
|
+
end
|
378
|
+
|
379
|
+
def render_add_new_resource!
|
380
|
+
attributes = send(add_new_resource_params_method_name).except(:id, :created_at, :updated_at)
|
381
|
+
self.resource = resource_scope.new(attributes)
|
382
|
+
|
383
|
+
@page_title = "New #{resource_name.titleize}"
|
384
|
+
flash.now[:success] ||= flash_success(resource) + ". Adding another #{resource_name.titleize} based on previous."
|
385
|
+
|
386
|
+
render(:new)
|
387
|
+
true
|
388
|
+
end
|
389
|
+
|
365
390
|
def referer_redirect_path
|
366
391
|
return if (resource && resource.destroyed? && request.referer.to_s.include?("/#{resource.to_param}"))
|
367
392
|
|
@@ -476,5 +501,10 @@ module Effective
|
|
476
501
|
["#{resource_name}_params", "#{resource_plural_name}_params", 'permitted_params'].find { |name| respond_to?(name, true) } || 'params'
|
477
502
|
end
|
478
503
|
|
504
|
+
def add_new_resource_params_method_name
|
505
|
+
method_name = resource_params_method_name
|
506
|
+
"add_new_#{method_name}" if respond_to?("add_new_#{method_name}", true)
|
507
|
+
end
|
508
|
+
|
479
509
|
end
|
480
510
|
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: 0.7.
|
4
|
+
version: 0.7.9
|
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-01-
|
11
|
+
date: 2018-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
85
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.5.2
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: Make any controller an effective resource controller.
|