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:
===================================================================================
<!DOCTYPE html>
<html>
<head>
<title>Subdomain</title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div id="container">
<div id="header">
<% if is_root_domain? %>
<h1>Sub<span class="off">Domain</span></h1>
<% else %>
<h1><%= @current_account.name %></h1>
<% end %>
</div>
<!--<div><%#=flash[:notice]%> <%#=flash[:alert]%></div>-->
<div id="menu">
<ul>
<% if user_signed_in? %>
<li class="menuitem"><a>Signed in as : <%=
current_user.email %></a></li>
<li class="menuitem"><%= link_to "Sign out",
destroy_user_session_path, :method => :delete %></li>
<% end %>
<% if !user_signed_in? %>
<% if is_root_domain? %>
<li class="menuitem"><a href="/">Home</a></li>
<li class="menuitem"><a href="#">About</a></li>
<li class="menuitem"><a href="#">Products</a></li>
<li class="menuitem"><a href="#">Services</a></li>
<li class="menuitem"><a href="#">Design</a></li>
<li class="menuitem"><a href="#">Contact</a></li>
<li class="menuitem"><%= link_to "Sign up",
new_user_registration_path %></li>
<li class="menuitem"><%= link_to "Sign in",
new_user_session_path %></li>
<% else %>
<li class="menuitem"><%= link_to "Sign in",
new_user_session_path %></li>
<% end %>
<% end %>
</ul>
</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>
</body>
</html>
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
--
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.