I have a problem where i have to send a session object through the Authorize method in pundit, but the authorize method only supports two parameters, current_user and records
Initially I created a new model named UserParam
class UserParam < ApplicationRecord
attr_reader :user, :session
def initialize(user,session)
@user = user
@session = session
end
end
Then I permited Application Policy to accept UserParam as an attribute:
class ApplicationPolicy
attr_reader :userParam, :user, :session, :record
def initialize(userParam, record)
@userParam = userParam
@record = record
end
delegate :user, to: :userParam
delegate :session, to: :userParam
Finally i overrode the user record used by pundit with an instance of UserParam class
def pundit_user
UserParam.new(current_user,session)
end
Then i called the authorize method as:
authorize @booking
After i run this code, i get error as:
BookingsController put #update for Owner should let owner update the booking to checkin when booking is active
Failure/Error: UserParam.new(current_user,session)
ArgumentError:
wrong number of arguments (given 2, expected 0..1)`