Skip to content

Instantly share code, notes, and snippets.

@victorcreed
Created February 6, 2014 11:15
Show Gist options
  • Save victorcreed/8842304 to your computer and use it in GitHub Desktop.
Save victorcreed/8842304 to your computer and use it in GitHub Desktop.
just for fun.... converted it into 1 line
class NewsLettersController < ApplicationController
def send_news_letter
#if params[:send_news_letter][:email].present?
# @user = User.new params[:send_news_letter]
# @user.save validate: false
# Notifier.send_news_letter(@user).deliver
# redirect_to root_path, notice: "Thanks for sharing. We'll keep you in the loop!"
#else
#redirect_to root_path, error: "Please provide your email for the newsletter."
redirect_to *lambda {lambda{ @user = User.new( params[:send_news_letter]); @user.save(validate: false); Notifier.send_news_letter(@user).deliver }.call if params[:send_news_letter][:email].present? ; return [root_path, (params[:send_news_letter][:email].present? ? { notice: "Thanks for sharing. We'll keep you in the loop!" } : {error: "Please provide your email for the news letter!"})] }.call
#end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment