Forum: Ruby on Rails Class reference from parsing a string?

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.
28b37e90e187bd316d7a0a180b004b29?d=identicon&s=25 warhero (Guest)
on 2006-12-22 22:59
(Received via mailing list)
Say I have a model class called Game. I also have a string call 'game'.
How can I do some parsing magic on the string to have a reference to
the model Game. So I can perform class methods. (Game.find(1))

thanks
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-12-22 23:31
(Received via mailing list)
On Dec 22, 2006, at 12:45 PM, warhero wrote:

>
> Say I have a model class called Game. I also have a string call
> 'game'.
> How can I do some parsing magic on the string to have a reference to
> the model Game. So I can perform class methods. (Game.find(1))
>
> thanks
>


'game'.camelize.constantize.find 1


-- Ezra Zygmuntowicz
-- Lead Rails Evangelist
-- ez@engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)
72f8ab180f81f9c544e2b58da399c0be?d=identicon&s=25 Elad Meidar - Creopolis.com (Guest)
on 2006-12-23 11:42
(Received via mailing list)
Vary dangerous, you need to be sure what is inside this string.
it's like the notorious Eval.
This topic is locked and can not be replied to.