Mel Mel - 1 year ago 449
Ruby Question

Rails Rolify with Pundit

The guidance in this post shows how to use rolify with pundit authorisations.

I'm trying to figure out how to this in my Rails app.

What's confusing me about the answer in the linked post is that the index action checks for

, where the show action checks for
. Is there a reason for the brackets in some cases?

Why is Pundit not coupled with Rolify like CanCanCan is?

def index?
@user.has_role? :admin

def show?
@user.has_role?(:admin) || @user.organisation == @organisation

Answer Source

Ruby allows you to leave out parenthesis, it's more like a coding style.

Normally we omit parenthesis when it comes to methods that are with keyword status in Ruby. (puts, attr_accessor etc.) for the rest methods, we can use ()

You can learn more on this here: Ruby Style Guide

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download