#2 ✓resolved
Brian Pokosh

bug with new_child_path

Reported by Brian Pokosh | April 24th, 2009 @ 08:44 PM

I might be doing something wrong, but when I tried new_chiild_path the route I get back has the parent resource pluralized.

Here are my routes:

map.with_options(:path_prefix => "admin", :name_prefix => "admin_") do |admin|
  admin.resources :pages, :has_many => :children

When I use new_child_path(:children) I get the back the route new_admin_pages_children_path which is incorrect. Want I should get is new_admin_page_child_path.

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson April 24th, 2009 @ 08:48 PM

    • State changed from “new” to “open”

    Yes, you are correct, have you tried using the latest version in the repo. I made some hardcore changes to the url methods, I believe it will fix this.

  • Brian Pokosh

    Brian Pokosh April 24th, 2009 @ 08:56 PM

    This is happening with the most recent code from github.

  • Ben Johnson

    Ben Johnson April 24th, 2009 @ 11:11 PM

    I am using this all over the place in my app and it is working great. The url you pointed out is wrong in many ways. There should never be "pages" in the url since it is a parent, it HAS to be off of an object. That just seems really weird. Can you give me an error or something? Also where are you calling this. Can you give me the exact url that this is being called from?


  • Ben Johnson

    Ben Johnson April 24th, 2009 @ 11:13 PM

    Also, you should be using:


    Since you are wanting to create a new child and not a new children, if that makes sense.

  • Ben Johnson

    Ben Johnson April 24th, 2009 @ 11:18 PM

    I know what you are doing. You calling new_child_path in your index action. You can't really create a new child when there is no object to create it off of. What object do you want it to be a child of? So you need to call this in an action where object is not nil. Or you can specify an object:

    new_child_path(:child, :page_id => 3)

    Lastly, "pages" doesnt have to be JUST a resource, it can be a context too. So if you did something like:

    map.with_options(:path_prefix => "admin/pages", :name_prefix => "admin_pages_") do |pages|
      pages.resources :children

    See how the above is just a context? Then your call would be correct:

    new_child_path(:child) => /pages/children/new

    Hope that makes sense.

  • Brian Pokosh

    Brian Pokosh April 25th, 2009 @ 01:20 AM

    I ended up scraping the whole pages :has_many => :children relationship so I can't test this out, but you're right, it was in an index view and I wasn't specifying the parent object.

    This should have worked fine though:

    new_child_path(:child, :page_id => 3)
  • Ben Johnson

    Ben Johnson April 25th, 2009 @ 01:27 AM

    • State changed from “open” to “resolved”

    Cool, thanks for updating

  • yolo

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Adds context into the RESTful development style.

People watching this ticket