Here's what you can do to make this work -
in ApplicationController
:
helper_method :current_person, :person_logged_in?
def authenticate_user!
redirect_to login_persons_path, alert: 'Please login to continue.' unless user_logged_in? # replace login_persons_path with the correct login route path
end
def current_person
@current_person ||= Person.find_by_id(session[:user_id])
end
def person_logged_in?
!!current_person
end
in your myblog.html.erb:
Use authenticate_user!
method in other controllers for before_filter
to check if user is logged in or not and to redirect them to login page if they're not.