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.
warhero (Guest)
on 2006-12-22 23: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
Ezra Z. (Guest)
on 2006-12-23 00: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 Z.
-- Lead Rails Evangelist
-- removed_email_address@domain.invalid
-- Engine Y., Serious Rails Hosting
-- (866) 518-YARD (9273)
Elad M. - Creopolis.com (Guest)
on 2006-12-23 12: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.