0

I'm using CanCan to authorize users' actions, and it works well, but now I need to display a message to user.

For example, user clicks on 'comment' button, and cancan checks for a following conditions:

  • User is activated
  • User is not banned
  • User registered > 1 day ago.
  • At least 10 minutes passed since user's last comment.

Now I have it in cancan's ability model, it tells user "you are not allowed to post a comment" if one of the conditions isn't true.

What is the best way to make messages more detailed? User should see an error like "Your account is not activated" and so on.

I thought to just put a code in controller, but I have not the only User, and I need to do the same at other controllers.

Alex
  • 2,309
  • 2
  • 16
  • 20

1 Answers1

0

Why don't you move these conditions into methods of the user model and use them in the Ability model and on the "access denied" page? As far as I know, cancan just says, if an action is allowed or now, but not why.

iGEL
  • 16,540
  • 11
  • 60
  • 74