2023-01-26

Does devise controller doesn't have access to database?

I'm trying to implement coupon/token functionality. In registration_controller.rb I'm trying to find token/coupon by its code and assign referred user to another user's referrer, but it (coupon) returns me nil.

However if I insert byebug and copy paste code in console, it works perfectly. Any ideas why this is happening?

Also controller assign different user than it should (for example: New user should be assigned to user ID 3, but it assigns it to user ID 15)

def create
  unless params[:user][:referrer_code].empty?
      # This returns nil
      coupon = Coupon.find_by(code: params[:user][:referrer_code])
      params[:user][:referrer_id] = coupon.referrer_id if coupon&.referrer && coupon&.multiple?
  end
  super
end


No comments:

Post a Comment