Given a symbol in rails, how do I get a Class? So I could call something like:
give_class(:post).find(:all)
or similar.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First, convert to string.
From there, you will need to format the string into a proper class name using the methods provided by ActiveSupport’s Inflector.
camelizewill turn'my_module'into'MyModule'classifywill turn'my_models'into'MyModel'camelizeis more likely the one you want, given your code snippet.Then use the
constantizemethod:Classy!