This project is archived and is in readonly mode.

#6346 ✓wontfix
Vladimir Meremyanin

Url_for should fail fast if :subdomain constraints in routes doesn't satisfy current request

Reported by Vladimir Meremyanin | January 30th, 2011 @ 01:54 AM

Suppose we have routes defined as

  constraints :subdomain => 'apples' do
    resources :apples
  end
  constraints :subdomain => 'oranges' do
    resources :oranges
  end

And in oranges#show (accessed from http://oranges.example.com/oranges/1 ) we need a link to an apple. Writing

  <%= link_to @apple.name, @apple %>

won't fail until you actually click the link and get the 404 error, because the link would have href="http://oranges.example.com/apples/1". So the suggestion is to consider current subdomain in url generation and if it doesn't satisfy constraints in routes raise error early.

By quick reading of url_for source code I didn't get the idea how to implement it correctly. Any suggestions on this?

Comments and changes to this ticket

  • Andrew White

    Andrew White February 14th, 2011 @ 06:32 AM

    • State changed from “new” to “wontfix”
    • Importance changed from “” to “Low”

    Constraints are tested against a request so to make your idea work you would need to construct a request that matches the link being clicked on and this would have a significant performance impact.

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