Forum: Ruby on Rails calling the controller in 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.
onurturgay (Guest)
on 2005-11-17 10:44
(Received via mailing list)
Hi,
I have string or symbol that holds a controllers name (like 'user' or
:user). How can I call one of the class methods of this controller?
Thanks in advance
dmitry (Guest)
on 2005-11-17 22:35
(Received via mailing list)
On Thursday 17 November 2005 15:42, Onur T. wrote:
> Hi,
> I have string or symbol that holds a controllers name (like 'user'
> or :user). How can I call one of the class methods of this
> controller?
Try:
str = "user" # or :user
kontroller = "#{str}_controller".camelize.constantize
kontroller.any_method_you_want
This topic is locked and can not be replied to.