Creating Twitter-style routes with Rails3

How can I create Twitter-style routes using Rails3?

I tried the following:

match ':username', :controller => "users", :action => "show"
match ':username/:controller(/:action(/:id))', :path_prefix => '/:username'

EDIT

After some extra copying through the docs, I did this and it seems to work:

scope '/:username' do
  resources :clubs
end

What is the scope method, and is there an automatic way to generate link_to links in my views?

+3
source share
2 answers

Next match will match /dhh/update/1

match ':username/update/:id' => 'updates#show'

'update#show' is new in Rails 3 and is a short version :controller => 'updates', :action => 'show'

0
source

Give it a try clubs_path(:username => 'bob').

0
source

Source: https://habr.com/ru/post/1765491/


All Articles