1

I have to create some type user friendly way of getting the user to login to there location.

Using devise for authentication. Company has subdomain field. Currently, if user signs in root, they also have to signin to the subdomain too.

Ideally, a user gets to the login screen and after they sign in, I could redirect them to the companies index controller. When they select a company, it redirects them to that companies subdomain and logs them in there.

Is there a way to store the login credentials and pass them to the subdomain after they select the subdomain?

Edit -

class Company < ActiveRecord::Base
    attr_accessible :name, :subdomain, :parent_id
end

class CompaniesController < ApplicationController
  def show
    @company = Company.find_by_subdomain!(request.subdomain)
  end
end

User such as District Manager can login and manage many companies. An employee can only login to a single company.

Being done so Manager can see what the other stores / companies are doing, but not employees.

pcasa
  • 3,710
  • 7
  • 39
  • 67

1 Answers1

0

I answered similar on this SO post... You'll want your cookies to be valid on all domains

Yourapp::Application.config.session_store :cookie_store, :key => '_yourapp_session', :domain=>:all 
Community
  • 1
  • 1
Jesse Wolgamott
  • 40,197
  • 4
  • 83
  • 109
  • Thought this would work, but it's not. If someone logs into root_url, that is taken over as logged in but they cannot logout. Nothing happens. If they login through one of the other subdomains, it then does not carry over that they are logged in. Also looked at other comments. – pcasa Feb 23 '11 at 00:39
  • @pcasa -- not doubting you, but this works -- if you set to auth cookie to all, then it exists in all subdomains and the main domain. What auth system are you using? – Jesse Wolgamott Feb 23 '11 at 13:40
  • Devise 1.1.5. Rails 3.0.3. Ruby 1.9.2p136. Did follow the railscasts http://railscasts.com/episodes/221-subdomains-in-rails-3. – pcasa Feb 25 '11 at 12:08