# Nester Resources, Routes and Class Inheritance

**URL:** <https://www.ruby-forum.com/t/nester-resources-routes-and-class-inheritance/152495>\
**Category:** Rails\
**Created:** [November 4, 2008, 4:46pm UTC](https://www.ruby-forum.com/t/nester-resources-routes-and-class-inheritance/152495 "2008-11-04T16:46:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [November 4, 2008, 4:46pm UTC](https://www.ruby-forum.com/t/nester-resources-routes-and-class-inheritance/152495/1 "2008-11-04T16:46:51Z")

</div>

Ok here’s a quicky… but a goody 🙂

We have models Company, Reference and Applicant… and References and  
Applicants just inherit from Company, and are basically companies with  
the type field set to reference…

All companies can have a phone number associated with them, and phone  
number is a different model…

I’m having trouble using the form\_for method with a company that  
happens to be an Applicant…

form\_for( [@company, @phone\_number] )

tries to use the route applicant\_phone\_number however the only route  
that exists is company\_phone\_number, which is the one I want to use…

I tried to create a route by creating a  
map.resource :applicants, :has\_many =\> phone\_numbers

but there is no resource for Reference or Applicant only models, and  
thus it breaks down… I get errors.

Any ideas on the correct way to make this work?

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [November 4, 2008, 9:34pm UTC](https://www.ruby-forum.com/t/nester-resources-routes-and-class-inheritance/152495/2 "2008-11-04T21:34:23Z")

</div>

On Nov 4, 9:46 am, sw0rdfish [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> happens to be an Applicant…
> 
> form\_for( [@company, @phone\_number] )
> 
> tries to use the route applicant\_phone\_number however the only route  
> that exists is company\_phone\_number, which is the one I want to use…

Yup, using an array in form\_for doesn’t work in STI situations like  
you’ve got.

You’ll have to do something like:

form\_for :company\_phone\_number\_path(@company, @phone\_number)

Jeff

[www.purpleworkshops.com](http://www.purpleworkshops.com)

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [November 4, 2008, 10:10pm UTC](https://www.ruby-forum.com/t/nester-resources-routes-and-class-inheritance/152495/3 "2008-11-04T22:10:17Z")

</div>

Ok so I tried your way, and I got an error;

compile error  
syntax error, unexpected ‘(’, expecting kEND  
\_erbout = ‘’; form\_for :company\_phone\_number\_path( [@company,  
@phone\_number] ) do |f| ; \_erbout.concat “\n”

So I did a little digging to see the syntax for it, and I came up with

\<% form\_for( [:company, @trade\_item] ) do |f| %\>

which seems to do the trick!

Quick Q, what does STI stand for, and what’s the proper syntax for  
your “version” ?

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [November 4, 2008, 11:33pm UTC](https://www.ruby-forum.com/t/nester-resources-routes-and-class-inheritance/152495/4 "2008-11-04T23:33:06Z")

</div>

On Nov 4, 3:09 pm, sw0rdfish [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> which seems to do the trick!

Interesting! I should have known that: by using the symbol, instead  
of an @ variable, it just uses the name ‘company’ instead of trying to  
inspect the @company class name.

> Quick Q, what does STI stand for, and what’s the proper syntax for  
> your “version” ?

Sorry: STI = “Single Table Inheritance”, the Rails term for using the  
“type” column in your table to help Rails figure out the right  
subclass for the object corresponding to that row in the table.

I think you’re getting the syntax error because you’re still using the  
array form [@company, @phone]. I just use

company\_phone\_path(@company, @phone)

where @company and @phone are just passed as regular arguments.

Jeff
