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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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.

thanks,

Bing
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
into
a symbol.

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

-Steve
http://www.stevelongdo.com
Bing (Guest)
on 2006-04-28 11:29
Hi Steve,

thanks so much, your solution works great!

Bing
This topic is locked and can not be replied to.