Instantly share code, notes, and snippets.

Embed
What would you like to do?
Referrals for rails user controller
# Add referrals only to new users
referred_by = params[:referred_by]
if referred_by.present?
if User.exists?(referred_by)
referrer = User.find(referred_by)
subscription = PaymentSystem.get_subscription(referrer.subscription_id)
if subscription.trial_end > Time.now.to_i
subscription.trial_end = (Time.at(subscription.trial_end) + 90.days).to_i
else
subscription.trial_end = (Time.now + 90.days).to_i
end
subscription.save
@user.referred_by = referred_by.to_i
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment