![](/img/trans.png)
[英]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.