Why is Pundit not affiliated with Rolify, like CanCanCan?

I use Devise and am interested in using Pundit, but I can not find much if it should integrate with Rolify or if it is standalone. CanCanCan works great with Rolify, and I like the role model. I am missing the main reason why Pundit and Rolify do not seem to be used together?

+8
ruby-on-rails-4 devise cancan rolify pundit
source share
2 answers

Why not use them together? They can be easily used in ways like this.

class OrganisationPolicy def initialize(user, organisation) @user = user @organisation = organisation end def index? @user.has_role? :admin end def show? @user.has_role?(:admin) || @user.organisation == @organisation end end 

In fact, the thing that rolify and pundit not connected is something nice, not a design failure;)

+35
source share

I recently used the Pundit gem with Rails 4 using devise. Pundit is a standalone Rolify-independent system, in accordance with my experience.

Instead of using Rolify, I created a migration to add roles to an existing user table, which allows you to assign roles to users and check what roles they have.

Please take a look at the diagram I created for my project:

  create_table "users", force: true do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.datetime "created_at" t.datetime "updated_at" **t.boolean "is_admin" t.boolean "is_daily_user" 

If the is_admin and is_daily_user fields are added for user roles.

Hope this helps!

+1
source share

All Articles