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.

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

#6346

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?

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

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

Activity

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

    February 14th, 2011 @ 06:32 AM