Skip to content

Instantly share code, notes, and snippets.

@knewter
Last active December 15, 2015 04:29
Show Gist options
  • Save knewter/5201992 to your computer and use it in GitHub Desktop.
Save knewter/5201992 to your computer and use it in GitHub Desktop.
class EmailSignupsController
# jQuery style:
def create
AcceptsEmailSignupForm.call(params).then(method(:successful_signup)).fail(method(:failed_signup))
end
protected
def successful_signup
render 'email_signups/thank_you' and return
end
def failed_signup(errors)
render('new', errors: errors) and return
end
end
class EmailSignupsController
# lambda style:
def create
AcceptsEmailSignupForm.call(params, {
success: ->{ render('email_signups/thank_you') },
failure: ->(errors){ render('new', errors: errors) }
})
end
end
class EmailSignupsController
# lambda style:
def create
AcceptsEmailSignupForm.call(params, {
success: method(:successful_signup),
failure: method(:failed_signup)
})
end
protected
def successful_signup
render 'email_signups/thank_you' and return
end
def failed_signup(errors)
render('new', errors: errors) and return
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment