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

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!

On Dec 15, 2007 10:49 AM, Stefano Bernardi
[email protected]
wrote:

How do i accomplish that?
This might help: 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/ as

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

and provide these named routes

root_url # => ‘http://www.example.com/
root_path # => ‘’

Thank you so much!

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

Thanks again!