RubyRedGrapefruit
RubyRedGrapefruit

Reputation: 12214

How can I tell on what page a user entered the application?

I have a Rails 3 application, and it consists of a main site and a series of branded subdomain sites. I need to find out how to check what a user's entry point so that I can decide when to put a link back to the main site.

How can I tell in Rails where someone entered the site?

Upvotes: 0

Views: 65

Answers (2)

gertas
gertas

Reputation: 17145

The best option is to share session across subdomains. I assume that you control all subdomains entirely then it will be secure as app with no subdomains.

Rails.application.config.session_store :cookie_store,  
                                   :key => '_app_session',  
                                   :domain => '.mydomain.com' 

Then on first entry remember the first subdomain name in session variable using filter.

session[:entry_host] ||= request.host

Link back should then look like

if session[:entry_host]
  link 'Home', root_url(:host => session[:entry_host])
end

Upvotes: 1

apneadiving
apneadiving

Reputation: 115511

You should store this information in session:

In you application_controller:

before_filter :check_entry_point

def entry_point
  # the ||= will let the first entry point alive
  session[:entry_point] ||= params[:controller] + params[:action]
end

Upvotes: 1

Related Questions