REST routes :has_many , new style

I am trying to write a nested route ‘new style’

map.resources :franchises, :has_many => :documents

in place of the :

map.resources :franchises do |franchises|
franchises.resources :documents, :name_prefix => “franchise_”
end

but get an error :
no route found to match “/franchises/1/documents” with {:method=>:get}

running rake routes, cannot see it…
what could be the problem with my Rail install ?

thanks

Kad K. wrote:

but get an error :
no route found to match “/franchises/1/documents” with {:method=>:get}

Shouldn’t ‘franchise’ be singular when used with an id?

John M. wrote:

Kad K. wrote:

but get an error :
no route found to match “/franchises/1/documents” with {:method=>:get}

Shouldn’t ‘franchise’ be singular when used with an id?

I tried it too…
no route found to match “/franchise/1/documents” with {:method=>:get}

a rake routes doesn’t show up any nested route for documents, it seems
the :has_many is not seen at all

Hi –

On Sat, 25 Aug 2007, Kad K. wrote:

but get an error :
no route found to match “/franchises/1/documents” with {:method=>:get}

running rake routes, cannot see it…
what could be the problem with my Rail install ?

Are you running edge Rails? If not, :has_many won’t work.

I’ve put your map.resources line in my routes.rb, and I get this in
the console:

r = ActionController::Routing::Routes
=> # lots of output…

r.recognize_path("/franchises/1/documents", :method => :get)
=> {:controller=>“documents”, :action=>“index”, :franchise_id=>“1”}

This is on revision 7340 (a fairly recent edge Rails).

David

David,
I am trying to figure out if this is the intended behaviour
map.resources :users,
:has_many => [:groups]

map.resources :groups, :collection => {:joined => :get, :created =>
:get}

in console I type

r = ActionController::Routing::Routes
r.recognize_path("/groups/created", :method => :get)
=> {:controller=>“groups”, :action=>“created”}

r.recognize_path("/users/diego/groups/created", :method => :get)
=> {:controller=>“groups”, :user_id=>“diego”, :action=>“show”,
:id=>“created”}

the collections routes for groups are not carried over into the nested
version inside of user.
Furthermore there is no syntax like has_many => [:posts =>
{:collections => {:joined => :get} } ] in place.

I am guessing that my only options is to repeat any :new, :member or
:collections specific routes.

Am I guessing right?

Diego

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs