Works great now. Thank you. Modified Code:
model_name = "User" @Model = model_name.constantize @Model.find(params[:id]).name On Feb 5, 10:32 am, Marnen Laibow-Koser <li...@ruby-forum.com> wrote: > Frank_in_Tennessee wrote: > > Good morning, > > > I'm trying to dynamically define models. > > > This method #1 works: > > model_name = User > > @Model = model_name > > @Model.find(params[:id]).name > > > This method #2 doesn't: > > model_name = "User" > > @Model = model_name > > @Model.find(params[:id]).name > > Of course not. In method 2, @Model is a String, not a Class. > > > Anyone know how I can get method #2 to work? Is there something I can > > tack onto the end of 'model_name' to get it to know that it's a model? > > Look up the constantize method. > > > > > Thanks, > > > Frank > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...@marnen.org > -- > Posted viahttp://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.