Class: User::RegistrationsController

Inherits:
Devise::RegistrationsController
  • Object
show all
Defined in:
app/controllers/user/registrations_controller.rb

Instance Method Summary collapse

Instance Method Details

#build_resourceObject (protected)

Override Devise::RegistrationsController#build_resource This is for updating the user with invitation.


86
87
88
89
# File 'app/controllers/user/registrations_controller.rb', line 86

def build_resource(*)
  super
  resource.build_from_invitation(@invitation) if @invitation && action_name == 'create'
end

#configure_sign_up_paramsObject (protected)

If you have extra params to permit, append them to the sanitizer.


54
55
56
# File 'app/controllers/user/registrations_controller.rb', line 54

def 
  devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
end

#createObject

POST /resource


18
19
20
21
22
23
24
25
# File 'app/controllers/user/registrations_controller.rb', line 18

def create
  User.transaction do
    super
    if @invitation && !@invitation.confirmed? && resource.persisted?
      @invitation.confirm!(confirmer: resource)
    end
  end
end

#invitation_paramObject (protected)


97
98
99
# File 'app/controllers/user/registrations_controller.rb', line 97

def invitation_param
  params.permit(:invitation)[:invitation]
end

#load_invitationObject (protected)


91
92
93
94
95
# File 'app/controllers/user/registrations_controller.rb', line 91

def load_invitation
  return if invitation_param.blank?

  @invitation = Course::UserInvitation.find_by(invitation_key: invitation_param)
end

#newObject

GET /resource/sign_up


8
9
10
11
12
13
14
15
# File 'app/controllers/user/registrations_controller.rb', line 8

def new
  if @invitation&.confirmed?
    message = @invitation.confirmer ? t('.used_with_email', email: @invitation.confirmer.email) : t('.used')
    redirect_to root_path, danger: message
  else
    super
  end
end

#select_layoutString? (protected)

Selects the layout for this controller.

This controller uses two layouts, one specially for editing users because it is in the context of the user administration panel.

Returns:

  • (String)
  • (nil)

80
81
82
# File 'app/controllers/user/registrations_controller.rb', line 80

def select_layout
  'user_admin' if ['edit', 'update'].include?(params['action'])
end