The following controller private method
def set_promotion
@promotion = Promotion.find(params[:id])
if !current_shopkeeper.nil?
@current_user = User.where(['email = ?', current_shopkeeper.email]).first
end
end
generates the @current_user
, but not the promotion instance variable.
In fact when inspecting the action
puts params[:id].class
puts @promotion
puts @current_user.id
puts Promotion.find(params[:id])
the values returned are
string
[blank_line]
16292
#<Promotion:.... >
even though the controller has the before_action defined, which kicks in given the current_user.id being returned
before_action :set_promotion, only: [:show, :edit, :update, :destroy]
the action literally required to call
@promotion = Promotion.find(params[:id])
to render the proper action.
Note: this is a controller that does not normally have access to devise's current_user and thus requires its own private method. Not sure if this impacts anything.
def pundit_user
User.where(['email = ?', current_shopkeeper.email]).first
end
What could be going on here?