Allow '.' to be a part of identifier, not a separator of format

Hi,

I have a question about available characters for url in Rails3.
Is it possible to include ‘.’ as identifier of resources?

Background

I want to use title name as identifier instead of id in url path, for
example:

http://localhost:3000/movies/Avatar

And I want to allow ‘.’ to appear in url, such as:

http://localhost:3000/movies/Avatar2.0

But it raises ActionController::RoutingError exception.

What I did

$ rails --version
Rails 3.0.0.beta2
$ rails g scaffold Movie title:string description:string
$ rake db:migrate
$ vi app/models/movie.rb
$ cat app/models/movie.rb
class Movie < ActiveRecord::Base
def to_param
title
end
end
$ rails c
irb> Movie.create(:title=>“Avatar”, :description=>“3D Movie”)

I accessed to http://localhost:3000/movies/Avator and page is shown
correctly.

But when I create another movie with title ‘Avator2.0’,
it causes ActionController::RoutingError.

ActionController::RoutingError in Movies#index

Showing /Users/kwatch/space/rails/myapp4/app/views/movies/index.html.erb where line #16 raised:

No route matches {:controller=>“movies”, :action=>“destroy”, :id=>#<Movie id: 2, title: “Avator2.0”, description: “Web 2.0 movie”, created_at: “2010-04-16 06:16:39”, updated_at: “2010-04-16 06:50:31”>}

I guess that ‘.’ may cause the error, but I want to allow to use ‘.’
in url.
Is it possible to use ‘.’ in url?

Environment

$ ruby --version
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10.2.0]
$ rails --version
Rails 3.0.0.beta2
$ uname -a
Darwin spica.local 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26
11:58:09 PST 2010; root:xnu-1504.3.12~1/RELEASE_I386 i386


regards,
makoto kuwata

In your ./config/routes.rb, you could do something like:


map.connect ‘/movies/:title’,
:controller=>‘movies’,
:action=>‘by_title’,
:requirements=>{:title=>/[-_+.a-z0-9]+/i}

See Regular Expressions and Parameters on
http://api.rubyonrails.org/classes/ActionController/Routing.html for
more info.

Jeff