dimanche 29 janvier 2017

Devise::SessionsController (bug?) - Unpermitted parameters

I had the error that appears in Devise Parameter Sanitizer "For" Method Not Found Rails 5

But after reading the solution a new error is appears in the console; I am trying to use simple_form with devise in Ruby 2.3.3p222 and Rails 4.2.3

Log:

Started POST "/users/sign_in" for ::1 at 2017-01-29 19:53:01 +0100
Processing by Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"vIcpPg5diOGlDzcwYfEW+SEnY75IQPdCDvcoOzrbNMk4ezv8/f4wkhCLPdFbJ6E4RG19e1+ikif5/GLpQPH0HQ==", "user"=>{"name"=>"Mike", "surname"=>"Nast", "email"=>"mikenast@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
  User Load (1.0ms)  SELECT  `users`.* FROM `users` WHERE `users`.`email` = 'josecr@gmail.com'  ORDER BY `users`.`id` ASC LIMIT 1
Completed 401 Unauthorized in 25ms (ActiveRecord: 1.0ms)
Processing by Devise::SessionsController#new as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"vIcpPg5diOGlDzcwYfEW+SEnY75IQPdCDvcoOzrbNMk4ezv8/f4wkhCLPdFbJ6E4RG19e1+ikif5/GLpQPH0HQ==", "user"=>{"name"=>"Mike", "surname"=>"Nast", "email"=>"mikenast@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
Unpermitted parameters: name, surname, password_confirmation

Also in my controller I have the:

      class Users::RegistrationsController < Devise::RegistrationsController


   prepend_before_action :require_no_authentication, only: [:new, :create, :cancel]
          prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy]
          prepend_before_action :set_minimum_password_length, only: [:new, :edit]

          before_action :configure_permitted_parameters, if: :devise_controller?

            def configure_permitted_parameters

              devise_parameter_sanitizer.permit(:sign_up, keys: [:name, :surname, :password_confirmation])

            end

In the sign_up view I have the following one:

<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
              <p><br/>

     <%= f.error_notification %>

        <div class="wrapper wrapper-content  animated fadeInRight">
          <div class="row">
            <div class="col-sm-8">
              <div class="ibox">
                <div class="ibox-content">

                  <div class="form-inputs">
                    <%= f.input :name, :label => 'First Name', required: true, autofocus: true %>
                    <br>
                    <%= f.input :surname, :label => 'Last Name', required: true, autofocus: true %>
                    <br>
                    <%= f.input :email, :label => 'Email', required: true, autofocus: true %>
                    <br>
                    <%= f.input :password, :label => 'Password', required: true %>
                    <br>
                    <%= f.input :password_confirmation, :label => 'Confirm Password', required: true %>
                    <br>
                  </div>

                  <div class="form-actions">
                    <%= f.button :submit, "Sign up" %>
                  </div>
                  <% end %>

Is there anything I missed or did wrong?

Aucun commentaire:

Enregistrer un commentaire