Question

I've searched the Web and Github and I see very few people using Rolify's callback options.

Rolify's callback options are (ref. https://github.com/EppO/rolify):

  • before_add
  • after_add
  • before_remove
  • after_remove

Example:

class User < ActiveRecord::Base
  rolify :before_add => :before_add_method

  def before_add_method(role)
    # do something before it gets added
  end
end

What are the typical usages of Rolify's callback options?

Was it helpful?

Solution

As a personal experience, to edit a field in the Users table after a role is added.

Having a web app and an api restricted to users with role :developer, after a user is assigned with that role I use the :after_add callback to create an access token for that user. You may need to remove the access token with :after_remove if the user isn't a :developer anymore.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top