Use variable_params && variable_params_attributes in project variables_controller.rb

This commit is contained in:
Shinya Maeda 2017-07-07 15:46:23 +09:00
parent 4fbfe475d8
commit 474d25e2e1
1 changed files with 8 additions and 4 deletions

View File

@ -12,7 +12,7 @@ class Projects::VariablesController < Projects::ApplicationController
end
def update
if @variable.update(project_params)
if variable.update(variable_params)
redirect_to project_variables_path(project),
notice: 'Variable was successfully updated.'
else
@ -21,7 +21,7 @@ class Projects::VariablesController < Projects::ApplicationController
end
def create
@variable = project.variables.create(project_params)
@variable = project.variables.create(variable_params)
.present(current_user: current_user)
if @variable.persisted?
@ -46,8 +46,12 @@ class Projects::VariablesController < Projects::ApplicationController
private
def project_params
params.require(:variable).permit([:id, :key, :value, :protected, :_destroy])
def variable_params
params.require(:variable).permit(*variable_params_attributes)
end
def variable_params_attributes
%i[id key value protected _destroy]
end
def variable