I had a question on Reflection. Assuming that I have an ActiveRecord object (Post). I know as an object we can do Post.find_by , Post.where . Can we do something like s= “Post” s.find_by s.where
What is the class of “s”? That class doesn’t support the #where method.
Actually I should have elaborated more. Lets say I have a page which takes the name of a Model. Example -> Post . On submit I need to get all the columns associated with the Model object. So I need to somehow dynamically find the value of “Post” which is a string and dynamically translate it to a Model object. I am from a java background and new to ruby. In java you can use reflection to create such dynamic objects passing string. I tried using model_obj = eval(“Post”) but somehow I get an error “NoMethodError (undefined method `coulmns’ for #):". Incidentally I do the same thing using Rails console and it works. It just doesn't work in the application. Please let me know if I am missing anything and also I want to thank you for the great screen cast it helped me a lot understanding ruby more.
If that’s the actual error message, then it;s simply that “columns” was misspelled.
|You must be logged in to comment|