Last active
December 10, 2015 11:39
-
-
Save johndel/4429406 to your computer and use it in GitHub Desktop.
Subscribe after it makes green the test. Some refactoring?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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