Skip to content

Instantly share code, notes, and snippets.

@johndel
Last active December 10, 2015 11:39
Show Gist options
  • Save johndel/4429406 to your computer and use it in GitHub Desktop.
Save johndel/4429406 to your computer and use it in GitHub Desktop.
Subscribe after it makes green the test. Some refactoring?
def subscribe
subscriber = Subscriber.where(email: params[:newsletter_email]).first
if subscriber
if subscriber.approval != "Approved"
NewsletterMailer.send_code_confirm(subscriber.email, subscriber.code_confirmation).deliver
redirect_to root_url, notice: "Σας εστάλη ένα email επιβεβαίωσης."
else
redirect_to root_url, notice: "Το email σας υπάρχει ήδη στη λίστα μας. Σας ευχαριστούμε για την εγγραφή!"
end
else
new_subscriber = Subscriber.new(email: params[:newsletter_email], approval: "Pending")
if new_subscriber.save
NewsletterMailer.send_code_confirm(new_subscriber.email, new_subscriber.code_confirmation).deliver
redirect_to root_url, notice: "Σας εστάλη ένα email επιβεβαίωσης."
else
redirect_to root_url, alert: "Μη έγκυρo email."
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment