Have SubscriberList
When an order is placed I want to check if New User’s email is all ready in our subscribers list.
If not, then add them. Problem is it adds them no matter what. Guess it’s not performing check correctly.
Currently in my orders_controller I have
unless logged_in?
@order.subscribe_after_purchase(@order.user.email)
end
And in my Order.rb I have
def subscribe_after_purchase(email)
unless SubscriberList.exists?(email)
SubscriberList.create(:email => email)
end
end
Try using:
When you just pass the email address to the
exists?method then ActiveRecord will interpret it as a primary key. Alternatively, you can use:—which will have the same effect as your
unlessblock; creating the record unless it already exists.exists?API documentation