10

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" into "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!

2 Answers 2

15

You have to modify the value directly, the instance variable does not point to the param, it just clones its value

params[:valueoftheparam] = 3
Sign up to request clarification or add additional context in comments.

Comments

1

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

2 Comments

I believe what he wants is getting a 3 when he does puts params[:valueoftheparam] in another method
@fernando I couldnt make it out from the question...then your answer is correct...we have to set params[:valueoftheparam] = "3".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.