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.

routing polymorphic/sti resources seems broken

#6137

Hi,

I have an Order class which is the root of 2 other STI classes

class VirtualOrder < Order; end

class ConcreteOrder < Order; end

I also have a single OrdersController and want my Orders, VirtualOrders and ConcreteOrders to be handled by that controller. This is something that worked in Rails-2.x.x using old style routing like this:

  map.resources :orders, :member => { :cancel, :return }
  map.resources :virtual_orders,  :as => :orders
  map.resources :concrete_orders, :as => :orders

This allowed my to do a:

  link_to "here", @polymorpic_order

Which is - imho - expected behaviour.

Now I am in the middle of migrating my project to Rails3 and my resources look like this:

  resources :orders do
    member do
      get :return, :cancel
    end
  end
  
  resources :virtual_orders,  :as => "orders"
  resources :concrete_orders, :as => "orders"

I fully expected to still be feeding duck-typed objects into link_to and get the link to work. Now that still is true, but;

  undefined method concrete_order_path for #<#<Class:0xe265be8>:0xe25bae4>

get's raised

Obviously making a helper for that fixes my problem real easily but that would only be KISS, not DRY (and I don't like wet kisses... ;->)

And now, to get down to it, is this a bug? Or was it a bug in Rails2?

Reported by coffeeaddict_nl · December 9th, 2010 @ 09:29 AM

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

Activity

  1. Ryan Bigg
    Ryan Bigg
    • State changed from new to resolved
    • Importance changed from to Low

    You should use :controller for this instead of :as.

    December 13th, 2010 @ 12:58 PM