rails change value of parameter in controller
I have this controller
def mymethod
@theparam => (params[:valueoftheparam])
@theparam => "3"
callothermethodthatusetheparam
end
So basically, I have "valueoftheparam" which is "2".
I need to change the value of "2" i开发者_如何学编程nto "3", and let "callothermethodthatusetheparam" the new param (which is "3") however, "callothermethodthatusetheparam" in the end still used the old value("2").How I can change this value in the controller, and let "callothermethodthatusetheparam" to use the new param value?
Thank you!
You have to modify the value directly, the instance variable does not point to the param, it just clones its value
params[:valueoftheparam] = 3
If you do like this, I am sure you will get 3 printed (@params will be "3")
def my_method
@param = (params[:valueoftheparam])
@param = "3"
other_method
end
def other_method
puts @param
end
精彩评论