Rails landing page routing and development

My site should work just like facebook.com. If the user is registered, and if he goes to "/", he must be processed by the home controller. If it is not logged, it must be processed by the landing_page .

"/ " && & user_signed_in? ---> home controller

"/" && & user_not_logged ---> dispatcher

I am using Rails 4 and Devise

ApplicationController

class ApplicationController < ActionController::Base before_filter :authenticate_user! end 

Routes.rb

 get "landing_page/index" root 'home#index', :as => :home 

How could I save the "before_filter" in the ApplicationControl that runs in each controller, except for the controller "landing_page"?

Update

If I go to the "/ en / landing_page_page" page, it will correctly display the landing_page descriptor (logged out), but if I go to "/", it will redirect me to "/ 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' 
+4
source share
3 answers

DECIDE!

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' 
+7
source

I think you could easily add a filter before processing this action.

Like in this answer

0
source

I think you can write the action of the confirm_logged_in function in the controller

before_filter: confirm_logged_in

In this function you can specify how you want to display pages based on a registered user

 def confirm_logged_in<br> unless session[:user_id] flash[:notice] = 'Please log in.' redirect_to(:controller => 'access', :action => 'login') return false #halts the before_filter< else return true end end 
0
source

Source: https://habr.com/ru/post/1493044/


All Articles