Skip to content

Pundit policy in cells

Shawn J. Goff edited this page Jan 16, 2014 · 2 revisions

Pundit provides a convenient policy helper method, but it is a global helper method that doesn't fit with the Cells way. Instead, create the policy object in your controler and inject that into your cell.

In your controller:

@policy = Pundit.policy(@user, @model_instance)

In your view:

render_cell(:some_cell, :some_state, :policy => @policy)

In your cell:

def some_state(opts)
  @policy = opts[:policy]
end