Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
simple_controller
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
simple_controller
Commits
e6cedb2f
Commit
e6cedb2f
authored
Dec 21, 2020
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add batch_create & batch_update methods to simple_controller
parent
6dd29f3e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
+44
-0
base_controller.rb
lib/simple_controller/base_controller.rb
+44
-0
No files found.
lib/simple_controller/base_controller.rb
View file @
e6cedb2f
...
...
@@ -65,6 +65,50 @@ class SimpleController::BaseController < ::InheritedResources::Base
end
end
def
batch_create
success_count
=
0
error_count
=
0
if
params
[
:transition
]
collection
.
transition
do
batch_create_params
.
each
do
|
create_params
|
collection
.
create!
create_params
success_count
+=
1
end
end
else
batch_create_params
.
each
do
|
create_params
|
begin
collection
.
create!
create_params
success_count
+=
1
rescue
error_count
+=
1
end
end
end
render
json:
{
success_count:
success_count
,
error_count:
error_count
},
status:
201
end
def
batch_update
success_count
=
0
error_count
=
0
if
params
[
:transition
]
collection
.
transition
do
collection
.
where
(
id:
params
[
:ids
]).
update!
permitted_params
end
success_count
=
collection
.
count
else
collection
.
where
(
id:
params
[
:ids
]).
find_each
do
|
_recourse
|
begin
_recourse
.
update!
permitted_params
success_count
+=
1
rescue
error_count
+=
1
end
end
end
render
json:
{
success_count:
success_count
,
error_count:
error_count
},
status:
201
end
protected
class
<<
self
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment