Q:

How do I stop routes for user profile conflicting with other routes in ruby on rails?

How would I stop these 2 routes from clashing:
  match "users/:id/edit", :to => "users#edit", :via => :get, :as => :settings
  match '/:username', :controller => 'users', :action => 'show'

When I visit localhost:3000/settings it tries to find a user in my users table with the username "settings".
What I plan on doing is having a page settings then have things like settings/privacy, settings/general and also edit_profile
How can I have this but also still get to user localhost:3000/username
It must be possible as I've seen many ROR sites doing this.
Kind Regards

A:

The settings route you have here is pointing to the users edit path.
Using settings_path will direct to users/:id/edit
What you want is:
match "/settings", :to => "users#settings"
match "/settings/:category", :to => "users#settings"
match '/:username', :controller => 'users', :action => 'show'

Now '/settings' will direct you to the settings method.  The second additional route will handle the specific setting to route to (ie /settings/privacy) which will allow you to evaluate what to do in the view based on the params[:category] parameter available in your settings action.  Alternatively this will give a privacy settings path:
match "/settings", :to => "users#settings"
match "/settings/privacy", :to => "users#settings", :as => :privacy_settings
match '/:username', :controller => 'users', :action => 'show'

No need for the :as statement, settings_path will still work.  Then in the settings method of your UsersController you can use session information(current_user) to render the proper user.
The RESTful edit path will be handled and available through this statement in your routes file:
resources :users

So 'users/:id/edit' will still work.

