Rails 4 multitencancy with login subdomain management

Scenario: a multi-level rails application that uses subdomains and develops a Problem: I want the user to be able to log in to mydomain.com and then redirect to the own address of the subdomain1.mydomain.com as a registered user. Right now, they can only enter their own subdomain.

I'm a relative newbie to Rails, and I can't find a simple solution (although it looks like it should be one). Ideally, I would like mydomain.com and subdomain1.mydomain.com to share the same cookie, but my skills do not exist for writing special middleware. Obviously, since this is a multienant, I cannot share one session in all subdomains. Stuck on this for a few days and am curious if there is a simple solution (like config.session_store domain setting) that I skip before I start looking at OAuth or other more bulky solutions. Any help would be appreciated!

Edit: Of course, I found this only after posting. Register the user in your subdomain after registering with Rails and Devise . Let's try the domain config.session_store :: all with a recommendation in front of the filter and send any details if this does not work, at least it seems like a good idea.

Edit: SOLUTION worked for my Devise setup with subdomain settings:

class ApplicationController < ActionController::Base

  before_action :check_subdomain

  def check_subdomain 
    unless request.subdomain == "" or request.subdomain == session[:subdomain]
      redirect_to request.protocol+request.domain
    end
  end

end

session_store.rb
My::Application.config.session_store :cookie_store, key: '_my_session' , :domain => :all, :tld_length => 2

[: ] . , : all session_store, . , request.protocol(http:// https://) + request.domain. ! .

+4
1

Cookie

, , , cookie . , cookie

: () Rails?

#config/initializers/session_store.rb
Your_App::Application.config.session_store :cookie_store, key: '_your_app_session', domain: :all, tld_length: 2

- tld_length - , "" ; IE, , tld_length,


Forwarding

, ; , .

"", Rails ( ), ,

-, , subdomain _url :

<%= link_to "Your Name", path_url(subdomain: "subdomain_1") %>

_path URL- , , subdomain. , _url URL ,

-

, , , . IE, , ,

+1

All Articles