Rails: 2.3.3

Overview: I want to enable cross domain session support. Eventually,
I'll have several domains for users to choose from, i.e.
user.domain1.com or user.domain2.com. I've borrowed from the code below,
but it doesn't seem to be working.


In middleware:

class SetCookieDomain

  def initialize(app, default_domain)
    @app = app
    @default_domain = default_domain
  end

  def call(env)
    host = env["HTTP_HOST"].split(':').first
    env["rack.session.options"][:domain] = custom_domain?(host) ?
".#{host}" : "#...@default_domain}"
    @app.call(env)
  end

  def custom_domain?(host)
    domain = @default_domain.sub(/^\./, '')
    host !~ Regexp.new("#{domain}$", Regexp::IGNORECASE)
  end
end

In environment.rb:

config.load_paths += %W(#{RAILS_ROOT}/app/middlewares)


In development.rb:

config.middleware.use "SetCookieDomain", ".mydomain.com"
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to