On 02 Mar 2009, at 14:12, fausto wrote:
> Hi, do you have any hint on how give to users the possibility to set
> an own domain instead of using a subdomain of the app? The best
> example i've found is how shopify works, they permit to have the shop
> under shopname.myshopify.com or set an own domain like shopname.com. I
> don't think they do this manually setting apache vhosts everytime..
> The A record of the own domain is the to the myshopify.com, but do you
> have hany idea on how manage this situation?
You need to set a wildcard A-record, change the vhost config to serve
the wildcard, then in a before_filter in your rails app handle the
subdomain. Quite easy actually.
DNS:
add *.mydomain.com as A-record and point it to same IP as the
mydomain.com one (if your host will allow it)
Apache Vhost config:
ServerAlias *.mydomain.com
....
Rails app (you could probably use account_location plugin to make it
easier on yourself):
class ApplicationController < ActionController::Base
before_filter :check_subdomain
def check_subdomain
if !account_subdomain
render :file => "#{RAILS_ROOT}/public/404.html", :layout =>
false, :status => 404 and return false
end
@current_site =
Account.find_by_subdomain(account_subdomain.downcase)
if !...@current_site
render :file => "#{RAILS_ROOT}/public/404.html", :layout
=> false, :status => 404 and return false
end
end
end
This is just a quick and dirty draft, you should adapt it to your
liking.
Best regards
Peter De Berdt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---