Forum: Ruby on Rails routes.rb noob question...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
internetchris (Guest)
on 2009-04-07 00:11
(Received via mailing list)
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
Freddy A. (Guest)
on 2009-04-07 00:30
(Received via mailing list)
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>
internetchris (Guest)
on 2009-04-07 01:30
(Received via mailing list)
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
Freddy A. (Guest)
on 2009-04-07 03:02
(Received via mailing list)
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 }
This topic is locked and can not be replied to.