[英]Rails routes for a static landing page if user not logged in
In my application I am using the Devise authentication gem which works really well.在我的应用程序中,我使用了非常有效的设计身份验证 gem。 I also have built a static landing page which I currently have in the /public
directory.我还构建了一个静态登录页面,目前在/public
目录中。
I can of course browser to localhost:3000/landing
and see the page (as per the route below) but what I'm trying to achieve but cannot seem to figure out is how to setup my routes.rb
file so that the landing.html
file is the root, but when a user is logged in, their root becomes companies#index
.我当然可以浏览到localhost:3000/landing
并查看页面(按照下面的路线)但是我试图实现但似乎无法弄清楚如何设置我的routes.rb
文件以便landing.html
文件是根目录,但是当用户登录时,他们的根目录变为companies#index
。
Here is my routes.rb file这是我的 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
Here is my application_controller.rb这是我的 application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
end
One way is to put the redirect inside your CompaniesController.rb
index
method do this.一种方法是将重定向放在CompaniesController.rb
index
方法中。
CompanesController.rb (or whatever it is called) CompanesController.rb(或任何名称)
def index
unless user_signed_in?
redirect_to landing_pages_path (or whatever the name of the route is)
end
end
Then change the route in the routes.rb
file.然后更改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.