Rails登陆页面路由和设计

spa*_*kle 4 ruby-on-rails rails-routing devise ruby-on-rails-4

我的网站应该像facebook.com一样工作.如果用户被记录并且如果它变为"/"则应该呈现为家庭控制器.如果没有记录,则应该渲染landing_page控制器

"/ "&& user_signed_in? ---> 家庭控制器

"/" && user_not_logged ---> landing_page控制器

我正在使用Rails 4和Devise

ApplicationController的

class ApplicationController < ActionController::Base

  before_filter :authenticate_user!
end
Run Code Online (Sandbox Code Playgroud)

的routes.rb

get "landing_page/index"

root 'home#index', :as => :home
Run Code Online (Sandbox Code Playgroud)

如何在ApplicationControl中保留一个"before_filter",除了"landing_page"控制器之外,它在每个控制器中运行?

更新

如果我转到"/ en/landing_page"它会正确渲染landing_page控制器(已注销),但如果我转到"/"它会将我重定向到"/ users/sign_in"

class LandingPageController < ApplicationController
  skip_before_action :authenticate_user!

  def index
  end

end

class ApplicationController < ActionController::Base

  before_action :authenticate_user!

end
Run Code Online (Sandbox Code Playgroud)

的routes.rb

 root 'landing_page#index'
Run Code Online (Sandbox Code Playgroud)

spa*_*kle 8

解决了!

LandingPageController

class LandingPageController < ApplicationController
  skip_before_action :authenticate_user!

  def index
  end

end
Run Code Online (Sandbox Code Playgroud)

HomeController的

class HomeController < ApplicationController
  skip_before_action :authenticate_user!
  before_action :check_auth

def check_auth
    unless user_signed_in?
        redirect_to :controller => :landing_page
    end
end
 end 
Run Code Online (Sandbox Code Playgroud)

ApplicationController的

class ApplicationController < ActionController::Base

  before_action :authenticate_user!

end
Run Code Online (Sandbox Code Playgroud)

的routes.rb

 root 'landing_page#index'
Run Code Online (Sandbox Code Playgroud)