Change url based on account name

Hi,

Is this possible

Can I specify a url ie
http://localhost/AccountName/:contorller/:action/:id

Where AccountName is should be a userName, which will lookup a siteId in
the database?

Whats the best way of going about this, is there somthing in the
routes.rb file I can change to get the account name into a variable?

Thanks for your help
jon

ok,

ive added this line of code to my routes file, that allows me to enter
the url http://localhost/host_id/controller

map.connect ‘:host/:controller/:action/:id’

How can I set rails to do Host.find(params[:host]) on load of every
page?

I have tried putting this in the application.rb but it just says
undefined local variable or method `params’ for
ApplicationController:Class

any suggestions?

thanks
jon

Can I specify a url ie
http://localhost/AccountName/:contorller/:action/:id

Where AccountName is should be a userName, which will lookup a siteId in
the database?

Yo!

you can specify the following routes…

map.connect ‘:user_name/:controller/:action/:id’
map.connect ‘:controller/:action/:id’

Then in ApplicationController

before_filter :set_site_id

def set_site_id
u = User.find_by_user_name params[:user_name]
params[:site_id] = u ? u.site_id : nil
return true
end

Then in your actions,

def some_action
@site = Site.find(params[:site_id])
end

Hope this helps…

Also, if you’re only going to use this route in a specific controller,
put the before_filter and accompanying action in it, instead of in the
application_controller, where it will be run before every request, not
just those run on the desired controller.

Ciao!
[email protected]
Gustav P.
itsdEx.com