title: Routing to different pages based on whether or not user is logged in. - Rails4
body: <p>in config/routes.rb, I have:</p>
  
  <pre><code>root to: "pages#home"
  get "/visitor" =&gt; "pages#visitor"
  </code></pre>
  
  <p>In my controllers/application_controller.rb, I have:</p>
  
  <pre><code>before_filter :route_relative_to_login_state_and_role
  
  private
  
  def route_relative_to_login_state_and_role
      if current_user
        redirect_to root_path
      else
        redirect_to visitor_path
      end
  end
  </code></pre>
  
  <p>In my controllers/pages_controller.rb, I have:</p>
  
  <pre><code>class PagesController &lt; ApplicationController
  
    before_action :authenticate_user!, :only =&gt; [:home]
  
    def home
      @page_title = t ('home_page_title')
    end
  
    def visitor
      @page_title = t ('visitor_page_title')
    end
  
  end
  </code></pre>
  
  <p>Here's my views/pages/home.html.erb</p>
  
  <pre><code>&lt;h1&gt;&lt;%= @page_title %&gt;&lt;/h1&gt; 
  </code></pre>
  
  <p>Here's my views/pages/visitor.html.erb</p>
  
  <pre><code>&lt;h1&gt;&lt;%= @page_title %&gt;&lt;/h1&gt; 
  </code></pre>
  
  <p>This is from the output of rake routes:</p>
  
  <pre><code>    visitor GET    /visitor(.:format)                       pages#visitor
  </code></pre>
  
  <p>When I start the server and point my browser to htp://localhost:3000 the browser tells me that the page is not redirecting properly. Here's what the log file says:</p>
  
  <pre><code>Started GET "/visitor" for 127.0.0.1 at 2014-05-15 10:37:46 -0700
  Processing by PagesController#visitor as HTML
  Redirected to http://localhost:3000/visitor
  Filter chain halted as :route_relative_to_login_state_and_role rendered or redirected       
  </code></pre>