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 constraints not working properly with regex

#4966
class UsersController < ApplicationController
  def show
    render :text => params[:id]
  end
end
R4963::Application.routes.draw do |map|
  resources :users
  match 'person/:id' => 'users#show'
end

With the above routing rule I can hit http://localhost:3000/person/ME

Now I changed the routing rules and added constraints.

R4963::Application.routes.draw do |map|
  resources :users
  match 'person/:id' => 'users#show', :constraints => { :id => /[A-Z]/ }
end

Now if I try to hit http://localhost:3000/person/ME I get no route matches exception.

Reported by Neeraj Singh · June 25th, 2010 @ 05:26 AM

State: invalid
Milestone: 3.x
Assigned to: nobody
Importance: Low

Activity

  1. Andrew White
    Andrew White
    • State changed from new to invalid

    Because you specified a single character id with the regexp

    June 25th, 2010 @ 07:06 AM

  2. Andrew White
    Andrew White

    To match http://localhost:3000/person/ME the routes would be:

    R4963::Application.routes.draw do |map|
      resources :users
      match 'person/:id' => 'users#show', :constraints => { :id => /[A-Z]+/ }
    end
    

    June 25th, 2010 @ 07:08 AM