我試圖用這種形式只更新電子郵件,但驗證失敗Current password can't be blank
,需要password_confirmation,我沒有線索如何失去此要求如何僅使用設計更新電子郵件?
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:method => :put, :id=>"email_form"}) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %>
<br/>
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.submit "Update" %></div>
<% end %>
UPDATE 這是我更新動作在overrided控制器RegistrationsController <設計:: RegistrationsController
class RegistrationsController < Devise::RegistrationsController
def update
@user = User.find(current_user.id)
successfully_updated = if needs_password?(@user, params)
@user.update_with_password(params[:user])
else
# remove the virtual current_password attribute update_without_password
# doesn't know how to ignore it
params[:user].delete(:current_password)
@user.update_without_password(params[:user])
end
if successfully_updated
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case his password changed
sign_in @user, :bypass => true
redirect_to after_update_path_for(@user)
else
render "edit"
end
end
private
def needs_password?(user, params)
user.email != params[:user][:email] ||
params[:user][:password].present?
end
end
這是已經適合你嗎? – calas