Last active
August 29, 2015 13:56
-
-
Save RichardJordan/9059538 to your computer and use it in GitHub Desktop.
Registration of user and account: RegistrationsController
This file contains 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
# see https://gist.github.com/RichardJordan/9059633 for explanation | |
# ----------------------------------------------------------------- | |
# in routes.rb - resources :registrations, only: [:new, :create] | |
class RegistrationsController < ApplicationController | |
include FormUtilities::GenerateHaikuName | |
attr_writer :registrar_source | |
respond_to :html | |
expose(:registration, attributes: :registration_params) | |
def new # maybe put back as responsibility | |
registration.shortname = create_haiku_name # of registration in an after_init | |
end # callback of some sort | |
def create | |
registrar.register registration | |
end | |
def create_registration_succeeded(registered) | |
self.current_user = registered.user | |
redirect_to registered.user, | |
notice: "Congratulations. Thank you for registering." | |
end | |
def create_registration_failed(not_registered) | |
self.registration = not_registered | |
render :new | |
end | |
private | |
def registrar | |
registrar = registrar_source.call(self) | |
end | |
def registrar_source | |
@registrar_source ||= Registrar.public_method(:new) | |
end | |
def registration_params | |
params.require(:registration).permit( | |
:email, :password, :password_confirmation, :fullname, :shortname) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment