1

When I submit a user registration, the POST params get passed, but I get error messages saying that email and password can't be blank. The form values also don't get filled in, and the user does not get entered into the database.
Here is my Registration view:

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), class: "register-form fts") do |f| %>
<div class="row">
<div class="col-md-3 col-lg-3 col-sm-1 col-xs-1"></div>
<div class="col-md-6 col-lg-6 col-sm-10 col-xs-10">
    <div class="column" style="text-align: center; margin: 0 auto;">
    <%= devise_error_messages! %>
    <div class="ui top attached message">
        <h3 class="ui header">Register</h3> 
        </div>
        <div class="ui large form attached segment" id="load-obj">
            <div class="two fields">
                <div class="field">
                    <%= f.text_field :firstname, "placeholder" => "First Name" %>
                </div>
                <div class="field">
                    <%= f.text_field :lastname, "placeholder" => "Last Name" %>
                </div>
            </div>
            <div class="field">
                <%= f.text_field :displayname, autocomplete: "off", "placeholder" => "Display Name" %>
            </div>
            <div class="field">
                <%= f.text_field :username, autocomplete: "off", "placeholder" => "Username" %>
            </div>
            <div class="field">
                <%= f.email_field :email, "placeholder" => "Email" %>
            </div>
            <div class="field">
                <%= f.password_field :password, autocomplete: "off", "placeholder" => "Password"  %>
            </div>
            <div class="field">
                <%= f.password_field :password_confirmation, "placeholder" => "Confirm Password", id: 'pcf'  %>
            </div>
            <%= f.submit "Sign up", class: "fluid ui green big button submit loader-detect", id: "reg_submit" %>

        </div>
        <div class="ui bottom attached message">
            <%= render "devise/shared/links" %>
        </div>
    </div>
</div>

<div class="col-md-3 col-lg-3 col-sm-1 col-xs-1"></div>
<% end %>


</div>
</div>

Here is my Registrations Controller

class RegistrationsController < Devise::RegistrationsController

    before_filter :update_sanitized_params, if: :devise_controller?

    protected

    def update_sanitized_params
        devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:username, :email, :password, :password_confirmation, :firstname, :lastname, :displayname)}
        devise_parameter_sanitizer.for(:account_update) {|u| u.permit(:firstname, :lastname, :email, :password, :password_confirmation, :current_password)}
    end
end

And here's my log file:

Started POST "/users" for 127.0.0.1 at 2014-12-02 16:22:57 -0800
Processing by RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"hUFEC/J3sjj1XolGwEVCcaI1K8baF2gE4xQVDhv6CoU=", "user"=>{"firstname"=>"John", "lastname"=>"Doe", "displayname"=>"JDoe", "username"=>"jdoe", "email"=>"john@doe.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
WARNING: Can't mass-assign protected attributes for User: username, email, password, password_confirmation, firstname, lastname, displayname

   (0.1ms)  begin transaction
   (0.1ms)  rollback transaction
  Rendered devise/shared/_links.erb (0.4ms)
  Rendered devise/registrations/new.html.erb within layouts/application (3.1ms)
Completed 200 OK in 227ms (Views: 215.6ms | ActiveRecord: 0.2ms)
Jojodmo
  • 23,357
  • 13
  • 65
  • 107
Un3qual
  • 1,332
  • 15
  • 27

1 Answers1

2

There's a warning

WARNING: Can't mass-assign protected attributes for User: username, email,
  password, password_confirmation, firstname, lastname, displayname

The warning means none of those attributes are successfully assigned with the values from the submitted parameters. So the object you try to save is a blank object. That's why you get errors saying username and email can't be blank. To resolve your problem, check out the accepted answer of this question.

Community
  • 1
  • 1
Hoa
  • 3,179
  • 1
  • 25
  • 33