How to handle permission in rails
class Post
has_many :post_users
has_many :users, through: :post_users
end
class PostUser
belongs_to :post
belongs_to :user
end
class User
has_many :post_users
has_many :posts, through: :post_users
end
How to handle permission in rails
class Post
has_many :post_users
has_many :users, through: :post_users
end
class PostUser
belongs_to :post
belongs_to :user
end
class User
has_many :post_users
has_many :posts, through: :post_users
end
How to handle permission in rails
class Ability
include CanCan::Ability
def initialize(user)
if user.present? # additional permissions for logged in users (they can read their own posts)
can :read, Post, users: { id: user.id }
end
end
end
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us