User_signed_in? not working when change subdomain

I am trying some different with devise

overload the devise session controller

class SessionsController < Devise::SessionsController
def new
super
end

def create
resource = warden.authenticate!(:scope => resource_name, :recall =>
:failure)
return sign_in_and_redirect(resource_name, resource)

request.host_with_port

end

def sign_in_and_redirect(resource_or_scope, resource)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
sign_in(scope, resource) unless warden.user(scope) == resource
subdomain_name = current_user.account.subdomain_name
if !current_account
redirect_to root_url(:host => “#{subdomain_name}” + “.” +
“#{request.host}”)
else
redirect_to root_url
end
end

end

My Application Controller is:

class ApplicationController < ActionController::Base
include UrlHelper
protect_from_forgery
helper_method :is_root_domain?
before_filter :current_account

def is_root_domain?
# return true if there is no subdomain
puts “++++++++++++++++++++++++++#{request.host_with_port}”
(request.subdomains(0).present? && request.subdomains(0) != “www”) ?
false : true
# request.subdomains.first.present? && request.subdomains.first !=
“www”
end

def current_account
# If subdomain is present, returns the account, else nil
if !is_root_domain?
@current_account ||=
Account.find_by_subdomain_name(request.subdomains(0))
if @current_account.nil?
flash[:notice] = “There is no Account with this subdomain”
redirect_to root_url(:account => false)
end
else
@current_account = nil
end
@current_account
end

end

And my application layout is:

===================================================================================

Subdomain <%= stylesheet_link_tag "application" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %>
<% if is_root_domain? %>

SubDomain

<% else %>

<%= @current_account.name %>

<% end %>
    <% if user_signed_in? %>
  • Signed in as : <%= current_user.email %>
  • <%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
  • <% end %> <% if !user_signed_in? %> <% if is_root_domain? %>
  • Home
  • About
  • Products
  • Services
  • Design
  • Contact
  • <%= link_to "Sign up", new_user_registration_path %>
  • <%= link_to "Sign in", new_user_session_path %>
  • <% else %>
  • <%= link_to "Sign in", new_user_session_path %>
  • <% end %> <% end %>
  </div>

  <% if user_signed_in? %>
    <div id="leftmenu">

      <div id="leftmenu_top"></div>

      <div id="leftmenu_main">

        <h3>Links</h3>

        <ul>
          <li><a href="#">Ruby</a></li>
          <li><a href="#">PHP</a></li>
          <li><a href="#">Ajax</a></li>
          <li><a href="#">jQuery</a></li>
          <li><a href="#">Web design</a></li>
          <li><a href="#">Web Programming</a></li>
          <li><a href="#">RAILS</a></li>
          <li><a href="#">Internet Marketing</a></li>
        </ul>
      </div>


      <div id="leftmenu_bottom"></div>
    </div>
  <% end %>




  <div id="content">


    <div id="content_top"></div>
    <div id="content_main">
      <%= yield %>
    </div>
    <div id="content_bottom"></div>
  </div>
</div>

now when I am trying to sign in from root means localhost it redirect to
subdomain.localhost
but cannot signin for that domain

if I remove subdomain from subdomain.localhost:3000 it shows the user in
his page
i.e user already signin

user_signed_in? not working for subdomain

If I signin from a subdomain then all are working correctly.
But when I am trying to signin from root domain I got the error

Somebody please help me

Thanks in advance

Kausik

Hi,

I am also working on a SAAS product. Please post you map.root line from
your route.rb files. It seems that something is wrong with your route
file. Either post the code of your route.rb (mainly the line map.root)
or check it by yourself.

Thanks.

My route file:

Subdomain::Application.routes.draw do

#devise_for :users
devise_for :users, :controllers => {:registrations => “registrations”,
:sessions => “sessions”}

root :to => “home#index”
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs