How to write CanCanCan Ability for user to read only their data?

How to write CanCanCan Ability for user to read only their data?

How do you restrict user access so a user can only read their own record?

How do you restrict user access so a user can only read their own record?

I've tried:

def initialize(user)
  can :read, User, :id => user.id

and this:

def initialize(user)
  can :read, user

but I can still access every user in index and show. I have authorize_resource in the UsersController.

Relevant documentation for reference:https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Ruby on Rails vs PHP

Understanding the pros and cons of Ruby on Rails versus PHP is important when deciding how to create your business-critical applications.