diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-01-13 03:46:43 +0300 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-02-05 20:57:42 +0300 |
commit | 121d84d774e18b27a8a4624f173e97cfad0d7f7c (patch) | |
tree | 21f9a7c0d493cbb09215b630c04363a31cd2c1a5 /app/controllers/projects | |
parent | fe96a1f268558526fd122a348866fbf513ac17e2 (diff) |
Implement multiple variable handling action
Diffstat (limited to 'app/controllers/projects')
-rw-r--r-- | app/controllers/projects/variables_controller.rb | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/app/controllers/projects/variables_controller.rb b/app/controllers/projects/variables_controller.rb index b7b88830837..f9d548a14f8 100644 --- a/app/controllers/projects/variables_controller.rb +++ b/app/controllers/projects/variables_controller.rb @@ -33,7 +33,20 @@ class Projects::VariablesController < Projects::ApplicationController end def save_multiple - head :ok + respond_to do |format| + format.json do + variables = [] + variables_params[:variables].each do |variable_hash| + variable = project.variables.where(key: variable_hash[:key]).first_or_initialize(variable_hash) + variable.assign_attributes(variable_hash) unless variable.new_record? + return head :bad_request unless variable.valid? + + variables << variable + end + variables.each { |variable| variable.save } + end + head :ok + end end def destroy @@ -54,6 +67,10 @@ class Projects::VariablesController < Projects::ApplicationController params.require(:variable).permit(*variable_params_attributes) end + def variables_params + params.permit(variables: [*variable_params_attributes]) + end + def variable_params_attributes %i[id key value protected _destroy] end |