The rails change the parameter value in the controller

I have this controller

def mymethod @theparam => (params[:valueoftheparam]) @theparam => "3" callothermethodthatusetheparam end 

So basically, I have a "valuetheparam" which is equal to "2".
I need to change the value of "2" to "3" and give "callothermethodthatusetheparam" a new parameter (which is equal to "3")
however, "callothermethodthatusetheparam" at the end still used the old meaning ("2").

How can I change this value in the controller and allow "callothermethodthatusetheparam" to use the new parameter value?

Thanks!

+4
source share
2 answers

You need to change the value directly, the instance variable does not point to the parameter, it just clones its value

 params[:valueoftheparam] = 3 
+10
source

If you do 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 
+1
source

Source: https://habr.com/ru/post/1339966/


All Articles