Rails - Dynamic routing based on host & ID

2019-07-28 16:09发布

问题:

I have a rails application that contains many user pages. When a user wants to point a domain at this page, how would I do that?

Right now I've tested out this, and it works -
root :to => "controller#show", :id => 4, :constraints => {:host => "www.exampleurl.com"}

but need to convert this to be dynamic, so that after I migrate a column into the model called domain it checks domain and serves it the proper ID.

something like -
root :to => 'controller#show', :id => ':id', :constraints => {:host => ':domain'}

What would something like this look like?