routing - User defined routes in Rails -
There is a lot of good information about routing in the rail; I should remember something, but I can not find a good example of rail applications Which allows dynamically-defined user-specific routes. For example, my app is hosted here:
www.thing.com
... and facilitates the user-generated content gives.
I want to give the user an option of defining a suffix, which shares somewhat customized URLs for their content. For example, if a user 'who' generates some car information, then they want to make it available through joescars:
www.thing.com/joescars
They may decide later that they want to serve under carbazo:
www.thing.com/carsbyjoe
Can I limit whether the suffix is valid Is there a way to codify this type of dynamic routing?
One way to do this is to type your config / routes
Add paths that say get '/: user_route' = & gt; 'Somecontroller # someaction'
. You have to put it down a lot because the routes are matched from top to bottom and will match things like / user
or you want to direct other routes elsewhere.
Then, in your controller, you can reach parameters [: user_route]
to show the appropriate content. Depending on your requirements, there are several ways to store this custom content in your database. You may represent these custom routes such as CustomRoute.find_by_route (params [: user_route])
, Or there may be a custom route for each user, so that you User.find_by_route (params [: User_route]). Custom_page
and each user
has a custom_page
.
Comments
Post a Comment