0
votes

I have table user and topic in my application. User who create topic has full ability of it and this user can grant ability to other user to access or edit. How can I implement this struct in cancan. I want something like

can? :edit, @topic

can :edit, Topic do |topic|
//get object @topic i pass above, and check current user has ability to edit this topic
end

I think about create new table name topic_share with topic_id and user_id. Many-many relation between topic and user. I don't know how to implement it in cancan.

2

2 Answers

0
votes

if your have some sort of creator_id on the topics table, you can do the following in cancan (assuming that your ability revolves around a user record and creator_id is the id of the user who created the topic and topic belongs_to user)

can :edit, Topic, creator_id: user.id
0
votes

I know this is not a direct answer, but you might want to take a look at this gem I created : https://github.com/intrepidd/rails-canhaz

It allows easily to create permissions between any model.