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

**URL:** <https://www.ruby-forum.com/t/allow-to-be-a-part-of-identifier-not-a-separator-of-format/187053>\
**Category:** Rails\
**Created:** [April 16, 2010, 9:04am UTC](https://www.ruby-forum.com/t/allow-to-be-a-part-of-identifier-not-a-separator-of-format/187053 "2010-04-16T09:04:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![makoto\_kuwata](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a4c791/32.png) [@makoto\_kuwata](https://www.ruby-forum.com/u/makoto_kuwata)\
**Post date:** [April 16, 2010, 9:04am UTC](https://www.ruby-forum.com/t/allow-to-be-a-part-of-identifier-not-a-separator-of-format/187053/1 "2010-04-16T09:04:29Z")

</div>

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](http://localhost:3000/movies/Avatar)

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

[http://localhost:3000/movies/Avatar2.0](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](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

---

<div class="post-metadata">

**Author:** ![makoto\_kuwata](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a4c791/32.png) [@makoto\_kuwata](https://www.ruby-forum.com/u/makoto_kuwata)\
**Post date:** [April 17, 2010, 5:17pm UTC](https://www.ruby-forum.com/t/allow-to-be-a-part-of-identifier-not-a-separator-of-format/187053/2 "2010-04-17T17:17:27Z")

</div>

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](http://api.rubyonrails.org/classes/ActionController/Routing.html) for  
more info.

Jeff
