views:

34

answers:

1

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
+2  A: 
John Topley
find_or_create_by_email works, forgot about that which this works too. You where right, needed to add the :email => email. But for some reason the "unless" block didn't work in my model. I changed it to "if" and put the code in the "else" section and it started to work.
pcasa