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
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 [email protected]
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
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 }