On Tue, May 3, 2011 at 2:33 PM, Michael Pavling <pavl...@gmail.com> wrote:
> On 3 May 2011 20:30, Michael Pavling <pavl...@gmail.com> wrote: > > On 3 May 2011 20:26, David Kahn <d...@structuralartistry.com> wrote: > >> record = > eval("#{associated_record_type}").find_by_id(associated_record_id) > >> > >> Is there a way to do this dynamically without using an eval? > > > > record = > associated_record_type.classify.constantize.find_by_id(associated_record_id) > > > > Actually, you might be better off with just .constantize - depends > what precise value you have in "associated_record_type" > Michael, thats just what I was looking for. It is a polymorphic situation and the value in the field is a string, so works out perfect. Thanks! > > record = > associated_record_type.constantize.find_by_id(associated_record_id) > > > http://api.rubyonrails.org/v2.3.8/classes/ActiveSupport/CoreExtensions/String/Inflections.html > > -- > 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-talk@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. > > -- 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-talk@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.