在服务器端向ActionController :: Parameters添加值

我想在服务器上为params添加一些值。

def my_params params.require(:my_model).permit(:my_field1, :my_field2, :my_field3) end def update # .................. # checking my_params["my_value"].class # => ActionController::Parameters my_params["my_value"] # => nil # adding my_params["my_value"] = "my value's value" # => "my value's value" # but it's still nil my_params["my_value"] # => nil # .................. end 

为什么我不能将它添加到my_params

my_params是一个方法而不是变量,而是使用实例变量,如下所示

 def my_params @my_params = params.require(:my_model).permit(:my_field1, :my_field2, :my_field3) end def update @my_params["my_val"] = "my value" #.... end