# Routes.rb noob question

**URL:** <https://www.ruby-forum.com/t/routes-rb-noob-question/164870>\
**Category:** Rails\
**Created:** [April 6, 2009, 10:11pm UTC](https://www.ruby-forum.com/t/routes-rb-noob-question/164870 "2009-04-06T22:11:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![internetchris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c68b51/32.png) [@internetchris](https://www.ruby-forum.com/u/internetchris)\
**Post date:** [April 6, 2009, 10:11pm UTC](https://www.ruby-forum.com/t/routes-rb-noob-question/164870/1 "2009-04-06T22:11:27Z")

</div>

Hey Everyone,

I’m wondering if the statement below are redundant? Once you define  
the resources for a particular controller, that should be it right?  
I’m assuming all I need is the second statement below.

map.resources :customers  
map.resources :customers, :has\_many =\> :accounts

Thanks!

Chris

---

<div class="post-metadata">

**Author:** ![internetchris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c68b51/32.png) [@internetchris](https://www.ruby-forum.com/u/internetchris)\
**Post date:** [April 6, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/routes-rb-noob-question/164870/2 "2009-04-06T22:30:11Z")

</div>

Yes all you need is the second statement. If you have both try running  
the command rake routes from the rails root directory it will show you  
what the two would do.(Or the one if you remove the top one.) THe  
second line could also be written like

map.resources :customers do |customer|  
customer.resources :accounts  
end

You would need that if you wanted to add a member or collections route  
to accounts

On Apr 6, 1:10 pm, internetchris [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![internetchris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c68b51/32.png) [@internetchris](https://www.ruby-forum.com/u/internetchris)\
**Post date:** [April 6, 2009, 11:30pm UTC](https://www.ruby-forum.com/t/routes-rb-noob-question/164870/3 "2009-04-06T23:30:32Z")

</div>

Hey Freddy,

So I’m not sure if my routes file is setup correctly after your last  
comment. Would you mind taking a look at it?

ActionController::Routing::Routes.draw do |map|

map.resources :customers, :has\_Many =\> :accounts  
map.resources :customers, :member =\> {:info\_for\_account\_form  
=\> :post}

map.resources :owners, :has\_many =\> :accounts  
map.resources :owners, :member =\> {:info\_for\_account\_form =\> :post}

map.resources :usertypes, :has\_many =\> :accounts

map.resources :accounts, :belongs\_to =\> :owner  
map.resources :accounts, :belongs\_to =\> :customer  
map.resources :accounts, :collection =\>  
{:auto\_complete\_belongs\_to\_for\_account\_customer\_name =\> :post}  
map.resources :accounts, :collection =\>  
{:auto\_complete\_belongs\_to\_for\_account\_owner\_name =\> :post}

# Install the default routes as the lowest priority.

map.connect ‘:controller/:action/:id’  
map.connect ‘:controller/:action/:id.:format’  
end

---

<div class="post-metadata">

**Author:** ![internetchris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c68b51/32.png) [@internetchris](https://www.ruby-forum.com/u/internetchris)\
**Post date:** [April 7, 2009, 1:02am UTC](https://www.ruby-forum.com/t/routes-rb-noob-question/164870/4 "2009-04-07T01:02:58Z")

</div>

Should look more like this:

map.resources :customers,  
:member =\> { :info\_for\_account\_form =\> :post },  
:has\_Many =\> :accounts  
map.resources :owners,  
:member =\> { :info\_for\_account\_form =\> :post },  
:has\_many =\> :accounts  
map.resources :usertypes,  
:has\_many =\> :accounts  
map.resources :accounts,  
:belongs\_to =\> [:owner, :customer],  
:collection =\>  
{ :auto\_complete\_belongs\_to\_for\_account\_customer\_name =\> :post,  
:auto\_complete\_belongs\_to\_for\_account\_owner\_name  
=\> :post }
