ruby-on-rails – Rails登陆页面路由和设计
发布时间:2020-12-17 03:40:13 所属栏目:百科 来源:网络整理
导读:我的网站应该像facebook.com一样工作. 如果用户被记录并且如果它变为“/”则应该呈现为家庭控制器.如果没有记录,则应该渲染landing_page控制器 “/ ” user_signed_in? — home controller “/” user_not_logged — landing_page controller 我正在使用Rail
我的网站应该像facebook.com一样工作.
如果用户被记录并且如果它变为“/”则应该呈现为家庭控制器.如果没有记录,则应该渲染landing_page控制器
我正在使用Rails 4和Devise ApplicationController的 class ApplicationController < ActionController::Base before_filter :authenticate_user! end 的routes.rb get "landing_page/index" root 'home#index',:as => :home 如何在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 的routes.rb root 'landing_page#index' 解决方法
解决了!
LandingPageController class LandingPageController < ApplicationController skip_before_action :authenticate_user! def index end end 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 ApplicationController的 class ApplicationController < ActionController::Base before_action :authenticate_user! end 的routes.rb root 'landing_page#index' (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |