Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8528285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:46:03+00:00 2026-06-11T08:46:03+00:00

What would be the best way to allow a logged-in user only access to

  • 0

What would be the best way to allow a logged-in user only access to a certain controller#action if condition X is met?

  • for example a user has deactivated his account ( user.is_deleted == true )
  • if the user logs in I want to redirect him to /reactivate
  • if the user tried any other url like /profiles /search it should redirect to /reactivate

I have tried before_filters in applicationcontroller with exceptions for the login and logout methods but they don’t work correctly messup with other actions so im really looking for a clean way to do this, anyone a suggestion?

Currently im using the

def after_sign_in_path_for(resource)
  @user = User.where(:id => current_user.id).first

  if @user.is_deleted == true
    "/reactivate"
  end

end

BUT *this only works on user login*
afterwards they can just do someting like /home /search etc
So i want to “lock-down” the app. I have thought perhaps instead of custom code one would need to do this with something like can can.

Do you know a working maintainable clean way to do this?

EDIT:

Did something like this ( you see to messy and breaks )

  def welcome_redirect
    if user_signed_in?
      if not current_user.welcome == 0
        if not params[:controller] == "home" && params[:action] == "welcome"
          if not params[:controller] == "modal"
            if not params[:controller] == "profiles"
              redirect_to profiles_path
            end
          end
        end
      end
    end
  end

EDIT 2:

This seems to work:

      def ensure_account_not_deleted
    if user_signed_in?
      @user = User.where(:id => current_user.id).first
      if params[:controller] != "users" && params[:action] != "reactivate" && @user.is_deleted == true
        redirect_to '/reactivate'
      end
    end
  end
  • another before filter was messing with some values causing this not to work I just found out ! thx all for the suggestions leading to this solution *
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:46:04+00:00Added an answer on June 11, 2026 at 8:46 am

    What’s wrong with:

    #Application Controller
    
    before_filter :ensure_account_not_deleted
    
    def ensure_account_not_deleted
      if params[:controller] != "users" && parmas[:action] != "reactivate" && @user.is_deleted == true
        redirect_to '/reactivate'
      end
    end
    

    EDIT:

    I wrote the code to exclude the reactivation from redirecting over and over again.

    I assumed here two things:

    1. The controllers which deals with reactivating is UsersController.

    2. The action is called “reactivate”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like the user to have limited access to controlling certain CSS attributes
I'm just wondering, as a hypothetical example, what would be the best way to
What is the best way to allow a user to do an arbitrary number
I was wondering what would be the best or easiest way to allow a
what would be the best way to allow sessions to be used across all
postgres 9.2 supports json columns. what would be best way to extend postgres to
I want to make a code snippet database web application. Would the best way
What would be the best way to something like this where a timestamp is
What would be the best way to display a dialog whenever my app receives
What would be the best way to version a rails application? We want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.