不允许的参数:current_password,Rails 4 + Devise [英] Unpermitted parameters: current_password, Rails 4 +Devise

查看:102
本文介绍了不允许的参数:current_password,Rails 4 + Devise的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个模式,注册用户可以更改其名称,电子邮件和密码。

I have created modal where registered user can change his name, e-mail and password.

问题:我无法更新用户数据。我尝试填写所有字段-当前密码和新密码。也尝试提交空表格,但是错误是相同的。

Problem: I can't update user data. I have tried to fill all fields - current password and new password. Also tried to submit empty form, but error is the same.

表格看起来像这样:

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { "data-parsley-validate" => true, :id=>"user-edit"},remote: true, format: :json) do |f| %>   

    <div class="form-group">
        <%= f.text_field :name,:class=>"user-input form-control", :id=>"user-name" ,:placeholder=> "Lietotājvārds*",:"data-parsley-group"=>"f1" %>               
    </div>

    <div class="form-group">    
        <%= f.email_field :email ,:class=>"user-input form-control", :id=>"password",:placeholder=> "E-pasts *",:"data-parsley-group"=>"f2" %>                            
    </div>   

    <div class="form-group">                  
        <%= f.password_field :current_password, :autocomplete => "off"  ,:class=>"user-input form-control", :id=>"password",:placeholder=> "Vecā parole*                       ",:"data-parsley-group"=>"f3" %>  
    </div>

    <div class="form-group">                      
        <%= f.password_field :password , :class=>"user-input form-control", :id=>"password",:placeholder=> "Jaunā parole*                       vismaz 8 simboli ",  :"data-parsley-group"=>"f3" %>  
    </div>

    <div class="form-group">                        
       <%= f.password_field :password_confirmation , :class=>"user-input form-control", :id=>"password",:placeholder=> "Atkārtot paroli *                     vismaz 8 simboli ",  :"data-parsley-group"=>"f3" %>      
    </div>

    <button type="submit" class="blue-button btn btn-default">Apstiprināt</button>
<%end%>

在路线中:

 devise_for :users,  :controllers => {:registrations=> "registrations"}

注册控制器:

class RegistrationsController < Devise::RegistrationsController 

    clear_respond_to   
    respond_to :json

   def sign_up_params
    params.require(:user).permit( :email, :password, :password_confirmation,:name, :not_a_robot)
  end
  def account_update_params
    params.require(:user).permit(:name, :email, :password, :password_confirmation, :current_password, :not_a_robot)
  end
  private :sign_up_params
  private :account_update_params


end

应用程序控制器:

 before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters

    devise_parameter_sanitizer.for(:update) { |u| u.permit(:name, :terms_of_service, :not_a_robot, :role,:im_old, :password, :current_password, :password_confirmation, :humanizer_question_id, :humanizer_answer,:email) }
      devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :terms_of_service, :not_a_robot, :role,:im_old, :password, :password_confirmation, :humanizer_question_id, :humanizer_answer,:email, :current_password) }
  end

我的日志文件:

Started POST "/ru/users" for 212.93.105.32 at 2015-09-27 15:59:24 +0300
Processing by RegistrationsController#create as JS
  Parameters: {"utf8"=>"✓", "user"=>{"name"=>"OPARRKRR", "email"=>"", "current_password"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "not_a_robot"=>"1"}, "locale"=>"ru"}
  [1m[36mBanlist Load (0.6ms)[0m  [1mSELECT `banlists`.* FROM `banlists`  WHERE (ip_adress = '212.93.105.32')[0m
  [1m[35mCountry Load (1.0ms)[0m  SELECT  `countries`.* FROM `countries`  WHERE `countries`.`id` = 1 LIMIT 1
  [1m[36mRegion Load (0.7ms)[0m  [1mSELECT `regions`.* FROM `regions`  WHERE `regions`.`country_id` = 1[0m
Unpermitted parameters: current_password
  [1m[35m (0.4ms)[0m  BEGIN
  [1m[36m (0.3ms)[0m  [1mROLLBACK[0m
Completed 422 Unprocessable Entity in 325ms (Views: 2.3ms | ActiveRecord: 20.9ms)


推荐答案


不允许的参数:current_password

Unpermitted parameters: current_password

您需要 白名单 <$ c $在 sign_up_params

def sign_up_params
  params.require(:user).permit( :email, :password, :password_confirmation, :current_password, :name, :not_a_robot)
end

这篇关于不允许的参数:current_password,Rails 4 + Devise的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆