Thanks for this Ryan!
I've been trying to get Devise and subdomains to work together, by using one of the Subdomain plugins, but not managed to get there fully. Going to have a go using your approach now and see how I get on.
Keep up the great casts, they are always mega helpful!
There is a typo in "http://github.com/ryanb/railcasts-episodes/tree/master/episode-221" link: it should be "http://github.com/ryanb/railscasts-episodes/tree/master/episode-221" (missing "s" in railscasts-episodes".
Another great screencast Ryan. Thank You. And as a side note, today's my birthday :)
Finally got Rails 3 working with RVM. Stopped using my local Passenger installation and now I'm really enjoying the flexibility of jumping around to different versions of Ruby/Rails.
Currently developing an app that requires account level subdomains and was unhappy with the options in Rails 2.3...
Looking forward to Rails 3 RC, thanks again for all the awesome screencasts!
Cool tricks, Ryan.
You just gave me some ideas to try out on my pet projects :)
Great vid, was meaning to have a look at the subdomains in rails3, but you just summed it up nicely.
Also plus points for picking up on smackaho.st :)
In this line of your code:
options[:host] = with_subdomain(options.delete(:subdomain))
what does options.delete() do? It doesn't seem intuitive, which is rare in Ruby.
--dhc
Is it possible to use domain size 0? I need to show different content depending on domain name, but the main part of the site is the same.
@dhc: It removes the passed element from the hash and returns it. See http://ruby-doc.org/core/classes/Hash.html#M002870
Very great episode. i've been waiting this for a long time.Thank you very much~Very good job
Hi, Ryan.
I've wrote similar article some months ago (http://bit.ly/ajGym2 - sorry, only Russian version, but you can use Google Translate) but there are some problems with session sharing between subdomains in Opera browser - unfortunately Opera cannot read cookies from sibling domain - it means if you set cookie for dom1.example.com cookie cannot be read from dom2.example.com
@Alexey Poimtsev:
There's a blog article on my.opera.com that describes how the Opera browser deals with cookie sharing between subdomains.
To sumarize (very quickly) the article: any *.example.tld subdomains are considered as siblings (and can share domain=.example.tld cookies) if the example.tld domain has a registered IP address in DNS.
The reality is a little more complicated, so the
http://my.opera.com/yngve/blog/show.dml/267415 article deserves a reading.
Thanks Ryan!
I really wish I had this to hand a couple of weeks ago when trying to figure out the subdomain stuff in Rails 3. This has helped me to tidy up my code somewhat.
I'd really like to see the ":subdomain" option on url helpers as a patch for Rails 3, will you be submitting? ...If not I may do so as it's super useful.
Thanks again.
@Alexander, I mention changing the top level domain size at the end of the episode. I haven't tested it, but passing "0" for the tld size should work.
@Jamie, I think the problem with adding a built-in :subdomain option is that the top level domain size is not easily configurable.
That said, I think a ticket on configuring the default tld size along with this would be great. I don't have plans to do this so feel free to.
I think
constraints(Subdomain) do
match '/' => 'blogs#show'
end
can be even shorter, like
constraints(Subdomain) do
root :to => 'blogs#show'
end
If you have to deal with various top level domains and third level assignments in parallel (.e.g. some have .com, some others co.uk) you may want to use the public suffix library from:
http://www.simonecarletti.com/blog/2010/06/public-suffix-list-library-for-ruby/
This is far better than hardcoding the length in your app and also used by browser vendors already.
hth,
Roland
You made my day Ryan! Thanks to you I moved a rather complex Rails app with various subdomain implementations from 2.3.8 to 3 in less than a day.
I just figured out how to get this working and blogged about it a couple of days before you did this! I like your solution more though. In case anyone is interested, I also blogged about how to test it with cucumber/capybara: http://mattbeedle.com/2010/07/04/testing-subdomains-with-cucumber-cabybara-and-rack-test
I just get an error...
uninitialized constant Subdomain (NameError)
Great screencast as usual, thanks Ryan !
On Mac OS X, "*.127localhost.*" resolves to 127.0.0.1 too: it's really helpful to test applications against both subdomains and TLDs.
Thanks for this post, but it don't work for ActionMailer.
Here my path:
http://gist.github.com/478169
güncel 2010 sitelerini buradan inceleyebilirsiniz. Bu sebeple bizde silere güncel 2010 sitlerini ve sub domainlerini yayınlayalım sitedik. Umarız faydalı olur ve yaralarnırsınız.
I am happy to find the site and I think it is very useful code to us.Thank you.
I am apreciating it very much.I have never read such a lovely article and I am coming back
If you get the error
uninitialized constant Subdomain (NameError)
it seems that in the later versions of the Rails 3 beta or the edge version the routes file doesn't autoload /lib/subdomain.rb
Adding
require 'subdomain'
before the routes block fixes this.
or the edge version the routes file doesn't autoload /lib/subdomain.rb
Adding
In Rails 3.0.0.rc there seems to be an issue using :domain => :all - it flips out with an InvalidAuthenticityToken error. Using :domain => ".smackaho.st" works for the time being.
Per https://rails.lighthouseapp.com/projects/8994/tickets/5147-the-all-domain-option-for-the-cookie-session-store-doesnt-allow-non-standard-tlds-like-local-or-couk
http://www.ndscardstore.com/Acekard
http://www.ndscardstore.com/R4
http://www.ndscardstore.com/DSTT
<a href="http://www.airjordanpower.com/air-jordan-dub-zeros-c-26" title="jordan dub zeros">jordan dub zeros</a>
<a href="http://www.airjordanpower.com/air-jordan-2010-c-25" title="air jordan 2010">air jordan 2010</a>
<a href="http://www.airjordanpower.com/air-jordan-2009-24" title="air jordan 2009">air jordan 2009</a>
<a href="http://dailysneakers.com/">sneaker news</a> <a href="http://dailysneakers.com/">puma shoes news</a> <a href="http://dailysneakers.com/">air jordan shoes news</a>
Thanks for this Ryan!
I've been trying to get Devise and subdomains to work together, by using one of the Subdomain plugins, but not managed to get there fully. Going to have a go using your approach now and see how I get on.
Keep up the great casts, they are always mega helpful!
your artical is very interesting, and i also have a brilliant website to share with you. http://www.worthmall.com .
thanks. you won't be a loss to visit it. maybe you can get something you are favorite.
@george (#35) : I agree.
It's weird that in the session_store.rb file, :domain => :all doesn't work for me (in Edge). :domain => 'lvh.me' does work though... any insights about this?
@docgecko (#2) : devise works fine for me here.
@Doug Mayer (#36):
@thb (#47):
:domain => :all doesn't work in the Rails 3 release candidate (it results in an InvalidAuthenticityToken error). The issue is resolved in Rails 3 master on GitHub with commit fd78bb72704554737117 by Bryce Thornton on 14 Aug 2010.
Thanks, Ryan! For anyone who needs more, I put together a Rails 3 example app (with a detailed walk-through tutorial) that shows how to set up subdomains in Rails 3 using Devise for authentication: http://github.com/fortuity/rails3-subdomain-devise (click above for the link). For anyone who needs a quick start for blog-style subdomains using Rails 3.
It's funny how we adopt words and adapt our lexicon to the times. This is a very useful slant on things.
love converse all star,love yourself.High quality low price.It's fit for you.
The blog article very surprised to me! Your writing is good. In this I learned a lot! Thank you!
Some times, to a certain need, we have to convert PDF to image for enjoyment.
Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it. My readers have about the same interets
InvalidAuthenticityToken error). The issue is resolved in Rails 3 master on GitHub with commit fd78bb72704554737117 by Bryce Thornton on 14 Aug 2010.
all doesn't work for me (in Edge). :domain => 'lvh.me' does work though... any insights about this?
@docgecko (#2) : devise works fine for me here.
Stopped using my local Passenger installation and now I'm really enjoying the flexibility of jumping around to different versions of Ruby/Rails.
Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it.
Extremely great post, really beneficial stuff. Never thought I’d find the facts I would like in this article. I’ve been looking all over the net for some time now and was starting to get irritated.






