# Polymorphic associations

**URL:** <https://www.ruby-forum.com/t/polymorphic-associations/117527>\
**Category:** Rails\
**Created:** [October 17, 2007, 6:34pm UTC](https://www.ruby-forum.com/t/polymorphic-associations/117527 "2007-10-17T18:34:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![destiney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@destiney](https://www.ruby-forum.com/u/destiney)\
**Post date:** [October 17, 2007, 6:34pm UTC](https://www.ruby-forum.com/t/polymorphic-associations/117527/1 "2007-10-17T18:34:50Z")

</div>

If i have the string ‘us\_address’ how can I use that to create an  
instance for a view?

@us\_address = UsAddress.new

Also, does anyone have a URL for how to construct forms for use with  
polymorphic associations? Everything I’ve seen up to now only shows the  
model relationships. How do you prepare to use this association in a  
form? What’s the best way to know what partial to load based on what  
model a particular association will use?

I need to use multiple address types, us, eu, etc.

Thanks,

–  
Greg D.  
Cyberfusion Consulting  
[http://cyberfusionconsulting.com/](http://cyberfusionconsulting.com/)

---

<div class="post-metadata">

**Author:** ![destiney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@destiney](https://www.ruby-forum.com/u/destiney)\
**Post date:** [October 18, 2007, 4:49pm UTC](https://www.ruby-forum.com/t/polymorphic-associations/117527/2 "2007-10-18T16:49:02Z")

</div>

On Wed, 17 Oct 2007, Greg D. wrote:

> If i have the string ‘us\_address’ how can I use that to create an instance for a view?
> 
> @us\_address = UsAddress.new

Some peeps from IRC helped me with this yesterday, so for posterity:

@address\_type = ‘us\_address’

@address = @address\_type.camelize.constantize.new

–  
Greg D.  
Cyberfusion Consulting  
[http://cyberfusionconsulting.com/](http://cyberfusionconsulting.com/)
