Customized Devise Form/Overridden Reg Controller

Why doesn’t this work? I’m using byebug to debug. All the parameters are there as intended.

Started POST "/users" for 127.0.0.1 at 2016-03-22 16:12:56 -0400
Processing by Users::RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"NjRZalKR067T+dchCQYJKdCCpXcCu5ljPMGA/r6t4pMZh2ZmyPL8cEUvX8usjBigqUI4w5Xfxjux+HxmQp029g==", "user"=>{"first"=>"wadson", "last"=>"wadson", "password"=>"[FILTERED]"}, "commit"=>"Sign up"}
   (0.1ms)  begin transaction
   (0.2ms)  rollback transaction
  Rendered devise/shared/_links.html.erb (5.4ms)
  Rendered devise/registrations/new.html.haml within layouts/application (20.5ms)
Completed 200 OK in 300ms (Views: 181.7ms | ActiveRecord: 0.4ms)

(byebug) params
{"utf8"=>"✓", "authenticity_token"=>"iV8+dZtxz0NFRE19fmkaH2KfEABJt6yUYoK9WLE47Sqm7AF5ARLgndOSxZfb4wuWG1+NtN7T88zvu0HATQg5Tw==", "user"=>{"password"=>"8005551212", "email"=>"homers@website.com"}, "commit"=>"Sign up", "controller"=>"users/registrations", "action"=>"create"}
(byebug)

registrations_controller.rb

  def account_email(first, last)
    "#{first.downcase}#{last.downcase.first}@website.com"
  end


  # POST /resource
  def create
    params[:user][:email]=account_email(params[:user][:first],params[:user][:last])
    super
    params[:user].delete(:first)
    params[:user].delete(:last)
  end

Below is my signup form…

new.html.haml

.container
  %h2 Sign up
  = simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
    = f.error_notification
    .form-inputs
      = f.input :email, required: true, autofocus: true, class: "form-control input-sm"
      = f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length)
      = f.input :password_confirmation, required: true
    .form-actions
      = f.button :submit, "Sign up"
  = render "devise/shared/links"

Turns out I had an attribute in my User model called “mobile” which was not included when submitting the form, therefore was not allowing Devise to authenticate with an empty field. I had renamed the label on the password field to "mobile and completely forgot to do a remove_column on the mobile attribute in the User model. Caught it by adding “devise_error_messages” to my signup form. Utilizing a TDD approach I would’ve caught this way sooner. Now this signup form works like a charm and generates an email address on the fly based on the inputs fields in the signup form.

Remember to add validations to your models and always check for blank or nil attributes it’ll make your life much easier.

Happy debugging!