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.

Path generation with array syntax and resources :as

#4722

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?

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

State: stale
Milestone: none
Assigned to: Andrew White Andrew White
Importance: Low

Activity

  1. Solly
    Solly

    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?

    May 29th, 2010 @ 06:47 PM

  2. Solly
    Solly

    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.

    June 2nd, 2010 @ 12:11 AM

  3. Solly
    Solly
    • 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

    June 5th, 2010 @ 01:00 AM

  4. Andrew White
    Andrew White
    • 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
    

    June 28th, 2010 @ 09:35 AM

  5. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 05:01 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 05:01 PM