我遇到Devise Parameter Sanitizer "For" Method Not Found Rails 5
中出现的错误但在阅读解决方案后,控制台中会出现一个新错误;我想在 Ruby 2.3.3p222和Rails 4.2.3
中使用simple_form和devise日志:
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
同样在我的控制器中我有:
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
在sign_up视图中,我有以下一个:
<%= 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 %>
我有什么遗漏或做错了吗?