Stefano Bernardi
2007-Dec-15 18:49 UTC
[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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bala Paranj
2007-Dec-16 00:34 UTC
Re: [REST] change :controller/:id/:action to :controller/:title/
On Dec 15, 2007 10:49 AM, Stefano Bernardi <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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?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 # => ''''> > > (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! > -- > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Stefano Bernardi
2007-Dec-16 01:12 UTC
Re: [REST] change :controller/:id/:action to :controller/:ti
Thank you so much! I did find the screencast this afternoon, but didn''t know about map.root! Thanks again! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---