0

I just implemented a new homepage using public/index.html which I read that it overrides a lot of the routes.

I originally had root to: static_pages#home and in my static_pages\home.html.erb view if a user was logged in, they saw the logged in homepage and the anonymous visitor (public/index.html) homepage if not logged in.

After implementing public/index.html, I created a new route for logged in users and made previous root_path redirects to home_path

get '/home' => 'static_pages#home', :as => :home

However, I would like to use http://localhost:3000 as the homepage for both logged in and visitor homepages. Is this possible? How can I have visitors see the current public/index.html which works good right now, but not have to use http://localhost:3000/home after login? I want http://localhost:3000 after login as well.

Thanks

user2159586
  • 203
  • 5
  • 16
  • You would need to code that or look for a filter that someone has made that changes what is included depending on the logged in cookie status. – tgkprog May 04 '13 at 00:43

2 Answers2

1

public/index.html is served by webserver before Rails, so you need another solution.

Instead you can move public/index.html into app/views/static_pages/index.html and edit your controller as follows:

class StaticPagesController < ApplicationController
  def home 
    if signed_in?
      # current content of #home action
    else
      render :index, :layout => false
    end
  end
end

or even more clean way

class StaticPagesController < ApplicationController
  before_filter :show_index_page, :only => :home

  def home 
    # the same
  end

private
  def show_index_page
    render :index, :layout => false unless signed_in?
  end
end
mikdiet
  • 9,859
  • 8
  • 59
  • 68
  • If I went back to my original home.html.erb method where I have `<% if signed_in? %>` and `<% else %>`, is there a code or something that I can use to make everything below `<% else %>` to have no existing formats / free from everything else? It appears that when I copy and paste what is currently inside public/index.html into there, the formatting is all off so I'm wondering if I can encase the code around something – user2159586 May 04 '13 at 00:50
0

What you need is a simple HomeController which render the right view for corresponding user.

You must have two erb view files for anonymous and signed in user.

Jahan Zinedine
  • 14,616
  • 5
  • 46
  • 70
  • how should the HomeController be like to render the right view? Is it just `class StaticPagesController` `def home` `if signed_in?` something here `else` something here `end`? – user2159586 May 04 '13 at 04:22