私はdeviseのパスワードなしでユーザーの属性を更新したいと思います。場合は、私はプロファイルを編集した後、私は更新プロファイルをヒット、私はプロファイルの編集ページに存在しないパスワードの検証エラーを取得しています!どのように私は念入りにこれを行うことができますか?プロファイルの編集ページに存在しないパスワードの検証エラーを取得しています。 Ruby on rails
モデル/ user.rb
validates :password, presence:true, :format => { :with => /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/,
:message => "Password should contain at least 6 characters, one upper case, one lower case and one numeric." }
私のアプリケーションのコントローラは、
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :configure_permitted_paramters, if: :devise_controller?
protected
def configure_permitted_paramters
devise_parameter_sanitizer.for(:sign_up) << :fullname
devise_parameter_sanitizer.for(:account_update) << :fullname << :phone_number << :description << :email << :password << :gender << :current_password << :avatar
end
end
私registrationscontrollerは、
class RegistrationsController < Devise::RegistrationsController
protected
def update_resource(resource, params)
resource.update_without_password(params)
end
end
マイedit.html /登録は、
ですされます<div class="row">
<label class="col-xs-4" for="fullname">Fullname</label>
<div class="col-xs-8">
<%= f.text_field :fullname, autofocus: true, :placeholder => "Full Name", :class => 'form-control' %>
</div>
</div></br></br>
<div class="row">
<label class="col-xs-4" for="date_of_birth">Date of Birth</label>
<div class="col-xs-8">
<%= f.date_select :date_of_birth, order: [:day, :month, :year], :start_year=>1910 %>
</div>
</div>
<div class="row">
<label class="col-xs-4" for="gender">Gender</label>
<div class="col-xs-8">
<%= f.check_box :gender, {}, false %> <%= f.label :gender, "Female" %>
<div class="col-xs-4">
<%= f.check_box :gender, {}, true %> <%= f.label :gender, "Male" %>
</div>
</div>
</div>
私のroutes.rbを私は更新プロファイルを打ったとき、それは、 表示され、
Rails.application.routes.draw do
root 'pages#home'
devise_for :users,
:path => '',
:path_names => {:sign_in => 'login', :sign_out => 'logout', :edit => 'profile'},
:controllers => {:registrations => 'registrations'}
resources :users
end
である「とは、少なくとも6つの文字、1大文字、1下部ケースと1つの数字が含まれている必要がありますパスワードを。」
私はパスワードなしで更新したいので、パスワードは編集登録フォームには表示されません。
これは 'on::update' helpedですか? – 7urkm3n
新規登録の場合、パスワードは1文字でも受け付けます – MSK
パスワード、長さ:{in:8..16}、:on: – MSK