routing - User defined routes in Rails -
there lot of info on routing in rails. must missing something, can't seem find illustration of rails application allows dynamically defined user specific routes.
for example, application hosted at:
www.thing.com
... , serves out user generated content.
i'd give user alternative define suffix let's them share customized url content. example, if user 'joe' generates auto info might want create avilable via joescars at:
www.thing.com/joescars
maybe later decide want serve out under 'carsbyjoe' at:
www.thing.com/carsbyjoe
i can handle limiting suffixs valid. there rails way codify kind of dynamic routing?
there way this. in config/routes
file add together route says get '/:user_route' => 'somecontroller#someaction'
. you'll have set @ bottom because routes matched top bottom , match things /users
or other routes you'll want directed elsewhere.
then, in controller can access params[:user_route]
show appropriate content. there number of ways store custom content in database, depending on needs. might have model representing these custom routes customroute.find_by_route(params[:user_route])
, or maybe each user have custom route user.find_by_route(params[:user_route]).custom_page
, each user
has 1 custom_page
.
ruby-on-rails routing routes
No comments:
Post a Comment