user1837021
user1837021

Reputation: 363

Rails: Redirect from everywhere to root location if not logged in

Is there a simple way to do this? How do I always trigger this controller, no matter on which page user tries to get?

Upvotes: 0

Views: 316

Answers (1)

Yanhao
Yanhao

Reputation: 5294

You can add a before_filter to ApplicationController:

before_filter :login_required

protected

  def login_required
    redirect_to root_url if not logged_in?
  end

Upvotes: 1

Related Questions