1

So I have my table users and each record has a username field

and I have my root to controller main and action `index

root :to => 'pages#main'

so if go to http://mydomain.com It'll show my main#index page and i have the about and contact pages as well.

but if i go to http://mydomain.com/Mr_Nizzle it shows me the page of the user Mr_Nizzle which is on users#show (just like example) and as well for the other users to show every user's page...

is it right if i go =>

match ':username' => 'users#show'

match 'contact_us' => 'main#contact'

match 'about' => 'main#about'

root :to => 'pages#main'

so i can leave all the logic on route instead of in the main controller?

Thanks.

Mr_Nizzle
  • 6,644
  • 12
  • 55
  • 85

1 Answers1

1

I'm not sure exactly what your asking, however this may be of some help. I think (at least for about and contact) the correct syntax is match '/contact_us' => 'main#contact (the same for about but replace contact with about), the root :to => 'pages#main' is correct (that's the same as doing match '/' => 'pages#main')

What are you asking about the match ':username' => 'users#show'? Do you want (for example) a url to be http://mydomain.com/users_username ? Where users_username is the name of the user's profile that they are navigating to? If so, i think you can do something like match '/:username' => 'users#show' but i'm not entirely sure.

Get back to me on what works and what doesn't

Vasseurth
  • 6,354
  • 12
  • 53
  • 81
  • 1
    Well yes the thing with `users_username` was exactly wy i was trying to do just had to turn my routes upside down for the priority of `about` and `contact_us` otherwise it'll be taking them as `:username` – Mr_Nizzle Jul 15 '11 at 20:53