[英]logged_in_user not working bypassing landing page for logged in users
[英]Rails routes for a static landing page if user not logged in
在我的应用程序中,我使用了非常有效的设计身份验证 gem。 我还构建了一个静态登录页面,目前在/public
目录中。
我当然可以浏览到localhost:3000/landing
并查看页面(按照下面的路线)但是我试图实现但似乎无法弄清楚如何设置我的routes.rb
文件以便landing.html
文件是根目录,但是当用户登录时,他们的根目录变为companies#index
。
这是我的 routes.rb 文件
Rails.application.routes.draw do
devise_for :users
get 'dashboard/index'
get '/landing', :to => redirect('/landing.html')
root 'companies#index'
resources :companies do
resources :shareholders
resources :captables do
post :subscribe_to_captable
resources :events do
post :lock_event
post :unlock_event
resources :transactions
end
end
end
end
这是我的 application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
end
一种方法是将重定向放在CompaniesController.rb
index
方法中。
CompanesController.rb(或任何名称)
def index
unless user_signed_in?
redirect_to landing_pages_path (or whatever the name of the route is)
end
end
然后更改routes.rb
文件中的路由。
get '/landing', to: 'companies#landing' * change companies here to the name of the controller holding the landing page's method if it is not in the companies controller.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.