Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Massive role checking via User#any_role? & Role#any?

Ilya N. Zykin the-teacher released this · 142 commits to master since this release

Massive role checking via User#any_role? & Role#any?

TheRole 2.1.0 provide following methods User#any_role? and Role#any? for massive checking of user's roles.

Now you can write following code:

  - if @user.any_role?(posts: :manage, pages: :manage)
      %h4 Publications:
      %ul
        - if @user.has_role?(:posts, :manage)
          %li= link_to 'My Posts', manage_user_posts_url(@user)

        - if @user.has_role?(:pages, :manage)
          %li= link_to 'My Pages', manage_user_pages_url(@user)

instead:

  - if @user.has_role?(:posts, :manage) || @user.has_role?(:pages, :manage)
      %h4 Publications:
      %ul
        - if @user.has_role?(:posts, :manage)
          %li= link_to 'My Posts', manage_user_posts_url(@user)

        - if @user.has_role?(:pages, :manage)
          %li= link_to 'My Pages', manage_user_pages_url(@user)

I hope it's will be usefull not only for me.

Have a nice day!

Downloads

Something went wrong with that request. Please try again.