Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 222
rahardi Avatar asked Feb 16 '11 09:02

rahardi


People also ask

What does params fetch do?

Returns a parameter for the given key.

What is action controller in Rails?

In the Rails architecture, Action Controller receives incoming requests and hands off each request to a particular action. Action Controller is tightly integrated with Action View; together they form Action Pack. Action Controllers, or just “controllers,” are classes that inherit from ActionController::Base .


1 Answers

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

params[:valueoftheparam] = 3
like image 54
Fernando Diaz Garrido Avatar answered Oct 08 '22 15:10

Fernando Diaz Garrido