Forum: Ruby on Rails Trying to turn params field into a variable

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bing (Guest)
on 2006-04-28 06:27
Hi guys,

I have another question, we have this line on our .rb code:

@variable = params [:user][:bird]

I need to be able to change the 2nd field into a variable because it is
a changing valuename, I was wondering if you had any trick for that.
Meaning I need to make [:bird] into [:dog] or [:cat]...

It's proven really tricky for me to get it to change I wonder if you
guys had any suggestions to it.


Steve L. (Guest)
on 2006-04-28 09:28
(Received via mailing list)
You should be able to use the to_sym method to turn your variable name
a symbol.

varname = "monkey"
@variable params [:user][varname.to_sym]

Bing (Guest)
on 2006-04-28 11:29
Hi Steve,

thanks so much, your solution works great!

This topic is locked and can not be replied to.