Pundit provides a set of helpers that guide Ruby programmer in leveraging regular Ruby classes and object oriented design patterns to build a simple, robust and scaleable authorization system.
Questions tagged [pundit]
439 questions
2
votes
1 answer
Rails 4 - Pundit - how to write a scope
Im trying to learn how to use Pundit with Rails 4. I have been trying to learn this for the last 2 years and am slowly making a tiny bit of progress.
I am also trying to learn how to write scopes. I'm still trying to figure out how to translate…

Mel
- 2,481
- 26
- 113
- 273
2
votes
3 answers
Rails 4 - pundit - how to write if statement to check user permissions
I'm trying to learn how to use pundit with my Rails 4 app.
I have a potential use policy. The potential use table has an attribute called :user_id.
I want users to be permitted to update instances if they created them. I'm trying to figure out how…

Mel
- 2,481
- 26
- 113
- 273
2
votes
2 answers
Pundit::NotDefinedError: unable to find policy `UserPolicy`
I must be doing something wrong or I need glasses. I am following this tutorial here:
http://vaidehijoshi.github.io/blog/2015/09/29/using-pundit-the-cool-kid-of-authorization/
I've created the application_policy.rb file and user_policy.rb files…

Zhang
- 11,549
- 7
- 57
- 87
2
votes
1 answer
ArgumentError at /user. - Rails 4 Rails_admin Pundit
I am trying to use rails_admin_pundit to add role based access
to rails_admin.
I am getting this error when I click on the users table in the rails_admin.
ArgumentError at /user. User(id: integer, email: string, ... 'shortened' ...role: integer) is…

David Gleba
- 517
- 1
- 5
- 21
2
votes
2 answers
Pundit policy_scope with Grape api
I am building API endpoints with Grape.
I have below scope:
class JourneyPolicy < ApplicationPolicy
def create?
user && user.identt_id == record
end
class Scope
attr_reader :user, :scope
def initialize(user, scope)
@user =…

przbadu
- 5,769
- 5
- 42
- 67
2
votes
0 answers
Pundit policy not initializing properly
I`m doing excercise from book Rails 4 in Action (listing 8-12). I installed pundit gem and wrote test, Rspec gives me strange error:
1) ProjectPolicy show? blocks anonymous users
Failure/Error:
def initialize(user, record)
@user = user
…

Leorisar
- 91
- 1
- 6
2
votes
1 answer
Pundit, the record has no my model attributes
i have a model CustomerProfile, with a column i24wholesaleid
In my Pundit policy CustomerProfilePolicy. i wanted to add some authorization logic to the show method so:
def show?
if ((user.wholesale? and record.i24wholesaleid ==…

Joel
- 81
- 7
2
votes
1 answer
rails leaving out some parts from fragment caching
I have a rails 4 app using pundit gem for authorization. If I do russian-doll fragment caching like the code below, the conditional statement used for authorization will be also cached, which is not good, since edit/delete buttons should only be…

Sean Magyar
- 2,360
- 1
- 25
- 57
2
votes
1 answer
How to test a Pundit Headless Policy?
Rails: 4.2
Pundit: 1.0.1
What's the strategy for testing headless policies? When I use the DSL given in the README examples, I run into issues with scoping.
The AdminPolicy:
class AdminPolicy < ApplicationPolicy
def initialize user, resource
…

Michael Lang
- 1,028
- 12
- 21
2
votes
2 answers
Pundit policy_scope error: undefined method `admin?' for nil:NilClass
Running into something I don't understand with Pundit,
Using Rails 4.2.5.1, Pundit 1.1.0 with Devise for authentication.
I'm trying to use a policy scope for the BlogController#Index action.
If user is admin, display all posts (drafts,…

Wasabi Developer
- 3,523
- 6
- 36
- 60
2
votes
1 answer
Render and/or redirect called multiple times in action
I'm using Devise and Pundit.
To create a new profile page, the user has to be authorized to do so.
This has been working fine since I first implemented it, but today it just started acting up with an error message:
Render and/or redirect were…

nope2023
- 1,668
- 1
- 15
- 28
2
votes
1 answer
Policy and case operator for the show view
I've got 3 types of users on my website :
visitors
members
VIP members (there is a vip attribute in User model)
Sports predictions are posted in the website but users don't have the same rights :
Visitors can only see past predictions
Members…

douvel
- 87
- 1
- 8
2
votes
0 answers
Splitting Pundit policies into sub folders
I have 2 parts to my application one for an API and then the normal Web application. Each have separate controllers, the API returns json and Web returns views
I am using Pundit for authorization and I would like to place my policies into sub…

Jeff Finn
- 1,975
- 6
- 23
- 52
2
votes
1 answer
How to set up authorization policies for two controllers using Pundit?
I'm learning Pundit using the RailsApps Pundit Tutorial and this statement from the tutorial totally confused me:
Given that the policy object is named UserPolicy, and we will use it
for authorization from the Users controller, you might wrongly…

Sergio Rodriguez
- 145
- 1
- 9
2
votes
1 answer
Multitenant scoping using Pundit
I'm using Pundit for authorization and I want to make use of its scoping mechanisms for multi-tenancy (driven by hostname).
I've been doing this manually to date by virtue of:
class ApplicationController < ActionController::Base
# Returns a single…

tristanm
- 3,337
- 2
- 27
- 40