0

ユーザーが状況に応じてアカウントの有無にかかわらずいくつかの詳細を変更できるように、少し工夫したgemをオーバーライドしました。

jQuery検証プラグインを使用しているため、deviseエラーメッセージを使用したくありません。

何らかのデバイスエラーが発生した場合に通知エラーを表示したいのですが、flash[:error] を配置する場所がわかりません。

ここに私の更新アクションがあります:

def update

self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
# custom logic
if params[:user][:password].present?
  result = resource.update_with_password(params[resource_name])
else
  result = resource.update_without_password(params[resource_name])
end

# standart devise behaviour
if result
  if is_navigational_format?
    if resource.respond_to?(:pending_reconfirmation?) && resource.pending_reconfirmation?
      flash_key = :update_needs_confirmation
    end
    set_flash_message :notice, flash_key || :updated
  end
  sign_in resource_name, resource, :bypass => true
  respond_with resource, :location => after_update_path_for(resource)
 else
   if params[:user][:password].present?
    clean_up_passwords resource
    render "edit_user/edit_password"
    end
  end

それで、誰かがこれで私を助けることができますか?

4

1 に答える 1

0

Jquery 検証を使用している場合は、同様のことを行ってビューでこれを有効にしましたか?<%= form_for @user, :validate => true, do |f|%>

更新 これに多少似たことができます

def update_password
    @user = current_user    
    @current_password = params[:user][:current_password]
    @password = params[:user][:password]

    if @user.valid_password?(@current_password)
      if @current_password == @password
        redirect_to user_path(@user)
        flash[:error] = "Current password cannot be the same as your new password."
      else
        if @user.update_attributes(params[:user])
          redirect_to login_path
          flash[:success] = "Password has been changed."
        else
          redirect_to user_path(@user)
          flash[:error] = "Didn't save contact an administrator."
        end
      end
    else
        redirect_to user_path(@user)
        flash[:error] = "Current password is incorrect."
    end
  end

私が提案したトップビットをビューに追加し、Jquery 検証を正しくインストールしていれば、これは機能するはずです

于 2012-09-26T08:48:00.903 に答える