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


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation