This project is archived and is in readonly mode.

#4722 ✓stale
Solly

Path generation with array syntax and resources :as

Reported by Solly | May 29th, 2010 @ 01:01 AM

Rails version: 3 beta 3
Ruby version: MRI 1.9.1
Ruby environment: mingw on Windows 7 (although this is probably irrelevant)

I have something similar to the following in my routes.rb:

resources :teachers do
  resources :school_classes :as => 'classes'
end

When I go to use the array syntax for path generation in form_for, as such:

form_for([@teacher,@school_class])

I get the following error:

undefined method `teacher_school_classes_path' for #<#<Class:0xa734060>:0xa731ac0>

I discovered that it seems to be calling model_name on the @school_class object, which returns the model_name, but not the appropriate name for path generation, which is slightly odd, since the named paths go as such: teacher_classes_path, and the teacher_school_classes form does not exists, so shouldn't the path generator know this?

Comments and changes to this ticket

  • Solly

    Solly May 29th, 2010 @ 06:47 PM

    After looking through the source code, it seems that if the code

    Resource.name
    

    (or the like) were used instead of

    RecordIdentifier.__send__("plural_class_name", record)
    

    everything would function well. Unfortunately, after digging for a while, I could not find any way to retrieve a Resource object after it is used in the mapping process. Any ideas?

  • Solly

    Solly June 2nd, 2010 @ 12:11 AM

    I'm thinking that the best way to handle this is to have a global hash (like the ActionController::Routing.routes array) that stores aliased path names. The entries would be added when resources :as was called, and then referenced during the call to polymorphic_url. I will work on creating a patch for this.

  • Solly

    Solly June 5th, 2010 @ 01:00 AM

    • Tag changed from rails3 routes, form_for, polymorphic_path, polymorphic_url, rails3, routing to rails3 routes, 3.0, form_for, polymorphic_path, polymorphic_url, rails3, routing
  • Andrew White

    Andrew White June 28th, 2010 @ 09:35 AM

    • State changed from “new” to “needs-more-info”
    • Assigned user set to “Andrew White”
    • Importance changed from “” to “Low”

    Are you looking to just change the url or do you want to change the path helper name as well?

    If you just want to change the url then this should do what you want:

      resources :teachers do
        resources :school_classes, :path => 'classes'
      end
    
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 05:01 PM

    • State changed from “needs-more-info” to “open”
    • Tag changed from rails3 routes, 3.0, form_for, polymorphic_path, polymorphic_url, rails3, routing to rails3 routes, 30, form_for, polymorphic_path, polymorphic_url, rails3, routing

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 05:01 PM

    • State changed from “open” to “stale”

Create your profile

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

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages