Hi --
Ernst Beiglböck wrote:
> I want to have the following URL structure
> /music
> /movies
> etc. for categories of the site.
>
> /about
> /help
> etc. for static pages.
This provides a custom homepage for any user: site.com/my_name
map.connect ':controller/:action/:id'
map.connect '*login', :controller => 'account', :action => 'home_page'
The trick is that param[:login] arrives in your controller.
I suspect I should have tested my system with this:
assert_routing '/mr_smith',
:controller => 'account',
:action => 'home_page',
:login => 'mr_smith'
Now you just read a *param in your controller, and render the appropriate
response.
I think you probably want :login, rather than *login. *login gives you
a route glob, which might contain any number of fields. They'll be
delivered to the action in an array (params[:login]), whereas with
:login you've got just one wildcard field, which will be delivered as
a string.
There's a bit of a potential problem with this route, though. If
someone has a login name that's the same as a controller, you might be
in trouble:
>> ActionController::Routing::Routes.recognize_path("/dblack")
=> {:login=>"dblack", :controller=>"account", :action=>"home_page"}
>> ActionController::Routing::Routes.recognize_path("/questions")
=> {:controller=>"questions", :action=>"index"}
If someone happens to sign up as "questions", their home page link
won't work. So it might be better to do something like:
map.connect 'home/:login', :controller => "account", :action => "home_page"
which gives you:
>> ActionController::Routing::Routes.recognize_path("/home/david")
=> {:login=>"david", :controller=>"account", :action=>"home_page"}
>> ActionController::Routing::Routes.recognize_path("/home/questions")
=> {:login=>"questions", :controller=>"account", :action=>"home_page"}
David