ruby on rails - How do I route user profile URLs to skip the controller? -


Now my user profile urls are like this:

and the user The controller indicates the show method.

What would I like to do? The user profile url offer is like this:

So, how to pull the path and how the controller magic Should be?

I agree about what JCM says about this. This is not a terrible idea and it is used by two major social networks Facebook and MySpace.

match http://example.com/username look like this:

  map.connect ': username',: controller = & Gt; 'User',: action = & gt; 'Show'  

If you want to go to the subdomain path and map profile on the URL such as http://username.example.com/ subdomainfu plugin and the resulting path This will look like:

  map.root: controller => 'User',: action = & gt; 'Show',: conditions => {: Subdomain = & gt; /.>  

These broad, must be defined in the final routes to catch all routes. RB, so that they are of the least priority, more specific routes will be matched first.

I also recommend using a verification in my user model to eliminate the possibility of choosing a user name in your user model, which will be hitting current and future routes:

  class user & lt; ActiveRecord :: Base validates_exclusion_of: user name, in: = in & gt; % W (message post blog forum admin profile) ... end  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -