Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

methods for routes not getting generated

#5293

In my app the following routes definition

resources :organizations do
  resources :branches
end

produces

No route matches {:controller=>"branches", :action=>"destroy",
   :organization_id=>#<Organization _id: 4c589f81c0b2101cd1000011, ...>,
   :id=>#<Branch _id: 4c589f81c0b2101cd1000012, ...>}

when I call it like this

organization_branch_path(organization, branch)

whereas this produces the correct url without errors

organization_branch_path(:organization_id => 23, :id => 23)

Notably the output of rake routes does not include the method name for GET but I am not sure if this used to be the case in earlier versions. The relevant output of rake routes is

                    GET    /organizations/:organization_id/branches(.:format)          {:controller=>"branches", :action=>"index"}
   organization_branches POST   /organizations/:organization_id/branches(.:format)          {:controller=>"branches", :action=>"create"}
 new_organization_branch GET    /organizations/:organization_id/branches/new(.:format)      {:controller=>"branches", :action=>"new"}
                         GET    /organizations/:organization_id/branches/:id(.:format)      {:controller=>"branches", :action=>"show"}
                         PUT    /organizations/:organization_id/branches/:id(.:format)      {:controller=>"branches", :action=>"update"}
     organization_branch DELETE /organizations/:organization_id/branches/:id(.:format)      {:controller=>"branches", :action=>"destroy"}
edit_organization_branch GET    /organizations/:organization_id/branches/:id/edit(.:format) {:controller=>"branches", :action=>"edit"}

I think it used to work like the version where you just pass instances of objects before and not having to think about the names of the required ids.

I have to mention that I am using Mongoid and do not have ActiveRecord included in my configuration. Not sure yet whether you do any reflection on that end - which IMHO would not be required to generate and/or recognize the routes. You can just call to_param on all objects being passed in order of nesting and associated the ids by convention, right?

Reported by Timo Mika Gläßer · August 4th, 2010 @ 11:10 AM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Timo Mika Gläßer
    Timo Mika Gläßer

    This is actually not a bug. The object was not yet stored in MongoId or ActiveRecord and after some digging I found that to_param calls persisted? and return nil if persisted? == false. So that solved it.

    August 4th, 2010 @ 12:42 PM

  2. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to invalid
    • Importance changed from to Low

    August 4th, 2010 @ 01:05 PM