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
1
vote
2 answers
user model error - Rails
Following is my user.rb:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:password_expirable, :confirmable, :lockable, :timeoutable,
…

EastsideDev
- 6,257
- 9
- 59
- 116
1
vote
2 answers
Setting Pundit role for user from Devise Registrations New View / Controller
I have both Pundit and Devise setup and working correctly in my rails app. However I am unsure about how to let the user decide their role when signing up.
At the moment:
I have a URL param which is passed to the Devise new view.
In the form_for I…

Tom
- 480
- 4
- 13
1
vote
2 answers
Error: uninitialized constant WillPaginate::ActionView (NameError) when using generator with Pundit
My app was using CanCan but now I'd like to switch to Pundit. I added Pundit to the Gemfile, deleted CanCan, ran bundle and then, when trying to run the generator (rails g pundit:install), I got the…

jasonweidner
- 49
- 1
- 8
1
vote
3 answers
Rails - Role based Views using Pundit
I am working on creating an app using Devise and Pundit to create users and assign them roles.
With that, I want to have role-based views in my app. I'm having a hard time thinking through how to make that possible.
When you login, if you're a user…

Luigi
- 5,443
- 15
- 54
- 108
0
votes
0 answers
Active Admin pundit adapter, cannot initialize pundit with custom attribute for active admin
Hey Guys I am using Active Admin gem for admin panel and Pundit for authorization.
Problem is I wanted new custom attribute in the policy scope so I modified it using pundit_user method in ApplicationController.rb Like this:
def pundit_user
…

Pavan Kumar V
- 592
- 6
- 17
0
votes
1 answer
Rails controller test defining current user
I'm having a small issue with testing in Rails 7 (API mode).
I try to set the current user manually in my test, this way, when the server resolve the route/method and controller, it checks for authentication, which is skipped in testing environment,…

OST
- 11
- 2
0
votes
0 answers
ActiveRecord::StatementInvalid in Summaries#index
PG::UndefinedColumn: ERROR: column summaries.user does not exist
LINE 1: SELECT "summaries".* FROM "summaries" WHERE "summaries"."use...
I'm trying to make a view restriction, where only the admin can see all the records in an app
0
votes
0 answers
Pundit Policy Scope with Ransack query
I am trying to use Ransack to filter records that have an applicable policy_scope from Pundit.
class ItemsController < ApplicationController
def index
@q = policy_scope(Item).ransack(params[:q])
@items = @q.result(distinct: true)
…

Romuloux
- 1,027
- 1
- 8
- 24
0
votes
2 answers
Why does a Pundit policy for one controller is affected by another?
I am perhaps misunderstanding Pundit policies but I am facing an issue where the UserPolicy is clashing with the SongPolicy.
What happens if that a statement in UserPolicy is being asserted ignoring what's written in…

csalmeida
- 528
- 7
- 26
0
votes
1 answer
How to check class in a policy's scope
Project is with Rails + Pundit. Fruit class has two subclasses:
Tropical < Fruit
Temperate < Fruit
In fruit_policy.rb I got this:
class Scope < Scope
def resolve
if user.is_near_equator
scope.where(class: Tropical)
else
…

nakakapagpabagabag
- 327
- 6
- 15
0
votes
1 answer
Authorizing by the parent model in rails using possibly pundit
I a simple relation
class Rental < ApplicationRecord
has_many :offers, dependent: :delete_all
end
and
class Offer < ApplicationRecord
belongs_to :rental
end
Within the OffersController I'm performing a few checks regardin the create action which…

Darksi
- 81
- 1
- 6
0
votes
1 answer
Ruby / Pundit -> user.owner_of?
I saw below in the pundit documentation and was wondering if that is part of some ruby or pundit magic based on user_id being present in a given model.
Or if it's just something they used to get a point across
https://github.com/varvet/pundit

BelgoCanadian
- 893
- 1
- 11
- 31
0
votes
2 answers
Rails/Devise/Pundit : Redirect after login if next action not authorized
I am using Rails 7, Devise and Pundit.
I've got Users and Projects.
Only Users classified as "admin" or "moderator" can perform actions (New,
Edit, Update, Destroy, ...).
Unlogged Users and Users classified as "user" can see Index and Show…

Aetherys
- 21
- 4
0
votes
2 answers
Pundit policy for personalized routes
I'm working on a rails app where I wrote a personalized route called "all_designs"; with the corresponding method on the controller and the view, before I add pundit to my project it was working fine.
Now I'm having this…
0
votes
0 answers
Extend ActiveRecord::Relation to prevent errors
I'm trying to generalize some logic to do some manipulation to a ActiveRecord::Relation. Issue is that the aim is to prevent authorization issues, so the flag needs to be set whenever a new ActiveRecord::Relation is instantiated or changed, but I'm…

Nuclearman
- 5,029
- 1
- 19
- 35