开发者

Custom URLs in Rails of the form custom.site.com

I would like to have my users specify custom URL paths开发者_开发问答 such that those paths are placed in front of my site's name, i.e. if I have a site called www.orion.com, I'd like a user to be able to create his own little home page at johnny.orion.com.

I have successfully managed to implement orion.com/johnny, which works implemented by adding map.connect ':path' at the end of my routes then making sure the path variable is present when needed.

How can I get johnny.orion.com to function?


First, you'll need to set up wildcard DNS - so that the subdomains actually resolve to somewhere.

Then, configure your virtual host to accept connections from these subdomains:

# If you're using Apache, something like:
ServerAlias *.orion.com

Then, you can use the subdomain-fu gem to handle your routes within Rails. Have a look at the associated Railscast for some good tips.

The syntax for the gem is something like this:

link_to 'Posts', post_path(@post, :subdomain => 'johnny')
johnny.orion.com/posts/4
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜