# \[REST\] change :controller/:id/:action to :controller/:title/

**URL:** <https://www.ruby-forum.com/t/rest-change-controller-id-action-to-controller-title/123273>\
**Category:** Rails\
**Created:** [December 15, 2007, 7:49pm UTC](https://www.ruby-forum.com/t/rest-change-controller-id-action-to-controller-title/123273 "2007-12-15T19:49:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mex23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@mex23](https://www.ruby-forum.com/u/mex23)\
**Post date:** [December 15, 2007, 7:49pm UTC](https://www.ruby-forum.com/t/rest-change-controller-id-action-to-controller-title/123273/1 "2007-12-15T19:49:35Z")

</div>

Ok, so this is the very very first time i use Ruby on Rails.

I’m developing a simple resource listing application

My question in simple:  
now to see a resource i would goto /resources/:id  
i want this to change to /resources/:permalink, with permalink being a  
field in my resources table.  
How do i accomplish that?

Also, is there a way to clean up the last 4 routes?  
I completely invented map.index because i didn’t know how to see my  
resurces listing in /, instead of typing /resources.

(i am sorry for the mess made by my resources controller, but i really  
needed to call it like this :D)

Here are my routes.

[code=]ActionController::Routing::Routes.draw do |map|  
map.resources :categories  
map.resources :resources

map.namespace :admin do |admin|  
admin.resources :resources  
admin.resources :categories  
end

map.resources :users  
map.resource :session, :controller =\> ‘sessions’

map.signup ‘/signup’, :controller =\> ‘users’, :action =\> ‘new’  
map.login ‘/login’, :controller =\> ‘sessions’, :action =\> ‘new’  
map.logout ‘/logout’, :controller =\> ‘sessions’, :action =\> ‘destroy’  
map.index ‘/’, :controller =\> ‘resources’, :action =\> ‘index’

end[/code]  
Thank You in advance!

---

<div class="post-metadata">

**Author:** ![mex23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@mex23](https://www.ruby-forum.com/u/mex23)\
**Post date:** [December 16, 2007, 1:34am UTC](https://www.ruby-forum.com/t/rest-change-controller-id-action-to-controller-title/123273/2 "2007-12-16T01:34:46Z")

</div>

On Dec 15, 2007 10:49 AM, Stefano Bernardi  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> How do i accomplish that?  
> This might help: [http://www.railscasts.com/episodes/63](http://www.railscasts.com/episodes/63)

> Also, is there a way to clean up the last 4 routes?

Use map.with\_options :controller =\> “sessions” do |page|  
page.login “/login”, :action =\> “new”  
page.logout “/logout”, :action =\> ‘destroy’  
end

> I completely invented map.index because i didn’t know how to see my  
> resurces listing in /, instead of typing /resources.

If you are using Rails 2.0, you can use map.root . From the docs:

Use map.root as a shorthand to name a route for the root path “”.

# In routes.rb

map.root :controller =\> ‘blogs’

# would recognize [http://www.example.com/](http://www.example.com/) as

params = { :controller =\> ‘blogs’, :action =\> ‘index’ }

# and provide these named routes

root\_url # =\> ‘[http://www.example.com/](http://www.example.com/)’  
root\_path # =\> ‘’

---

<div class="post-metadata">

**Author:** ![mex23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@mex23](https://www.ruby-forum.com/u/mex23)\
**Post date:** [December 16, 2007, 2:12am UTC](https://www.ruby-forum.com/t/rest-change-controller-id-action-to-controller-title/123273/3 "2007-12-16T02:12:12Z")

</div>

Thank you so much!

I did find the screencast this afternoon, but didn’t know about  
map.root!

Thanks again!
