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

Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

gurupal singh asked in Rails

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
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.