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'
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With