Skip to content

Lockdown Username Change

qnoox edited this page Oct 18, 2016 · 8 revisions
class ApplicationController < ActionController::Base
   before_action :configure_permitted_parameters, if: :devise_controller?

protected

 def configure_permitted_parameters
 added_attrs = [:username, :email, :password, :password_confirmation, :remember_me]
 lockdown = [:email, :password, :password_confirmation, :remember_me]
 devise_parameter_sanitizer.permit :sign_up, keys: added_attrs
 #You remove the :username this way it won't accept it when you change it.
 devise_parameter_sanitizer.permit :account_update, keys: lockdown
 end

Change registrations/edit.html.erb `

<%= f.label :username %>
<%= f.text_field :username, autofocus: true, class: 'form-control', :readonly => true %>
`

Congratulations Users can't change username now

Clone this wiki locally