Skip to main content

How to prevent users from view other user profile or data ?

Rails • Asked by gurupal singh

I have created 2 users (using devise gem) and added data in both the profiles, but both users can see each others data and profiles. How to stop users to access or see other users profiles


What does your controller look like for the action? You should be using the Devise helper method current_user.

For example, don't do this:

def show
  @user = User.find(params[:id])
end

Instead, do this:

def show
  @user = current_user
end

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.