Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails landing page routing and devise

My website should works just like facebook.com. If the user is logged and if it goes to "/" it should be rendered home controller. If it isn't logged it should be render landing_page controller

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

"/" && user_not_logged ---> landing_page controller

I'm 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 I could keep a "before_filter" in ApplicationControl that run in every controllers except "landing_page" controller?

Update

If I go to "/en/landing_page" it render landing_page controller correctly (logged out), but if I go to "/" it 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'
like image 405
sparkle Avatar asked Jan 13 '23 20:01

sparkle


1 Answers

SOLVED!

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'
like image 195
sparkle Avatar answered Jan 16 '23 19:01

sparkle