Reputation: 34944
I want to add some value I'm evaluating on the server to the 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
Why can't I add it into my_params
?
Upvotes: 1
Views: 4713
Reputation: 9782
my_params
is a method not a variable, use an instance variable instead, as below
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
Upvotes: 7