2012-04-17 10 views
1

サインインしたユーザーが自分の編集ページでプロファイル情報を変更できるようにするには、パスワードを入力する必要はありません。これはUsersControllerのですか?before_filterを変更してプロファイル編集にパスワードを必要としないようにする

がUserController:

before_filter :authenticate, :except => [:show, :new, :create] 
    before_filter :authenticate, :only => [:index, :edit, :update, :destroy] 
    before_filter :correct_user, :only => [:edit, :update] 
    before_filter :admin_user, :only => :destroy 



    def edit 
     @title = "Edit user" 
    end 

    def update 
     @user = User.find(params[:id]) 
     if @user.update_attributes(params[:user]) 
      flash[:success] = "Profile updated." 
      redirect_to @user 
     else 
     @title = "Edit user" 
     render 'edit' 
    end 
end 

編集ページ

 </div> 
    <h1> Confirm Password</h1><br /><br /> 
     <div class="field"> 
     <%= f.label :password, "Enter Password" %>&nbsp;&nbsp;&nbsp;&nbsp; 
     <%= f.password_field :password %> 
    </div> 
    <div class="field"> 
     <%= f.label :password_confirmation, "Confirm Password" %>&nbsp;&nbsp;&nbsp; 
     <%= f.password_field :password_confirmation %> 
    </div> 
    <div class="actions"> 
     <%= f.submit "Submit" %> 
    </div> 
    <% end %> 
    </div> 

答えて

0

私はあなたの質問を理解していません。ログイン時にユーザー名とパスワードを認証する場合は、プロファイルページを編集するためにパスワードを再入力する必要はありません。ログイン後、それは持続するはずです。認証宝石を使用していますか?ここで

def update_with_password(params={}) 
    if current_user && self.password.blank? 
    false 
    if params[:password].blank? 
     params.delete(:password) 
     params.delete(:password_confirmation) if params[:password_confirmation].blank? 
    end 
    else 
    super 
    end 
end 
+0

私は知っているわけではありません。ちょうど私の編集(更新)ページでは、画像のアップロード時にパスワードを確認するためのフォームがあり、パスワードが入力されていなければ機能しません。 – Elias7

+0

非常に奇妙なことに、私はあなたが認証だと書いています。それは非常に非実用的な認証の使用です。 [Rails Tutorial Sessions](http://ruby.railstutorial.org/chapters/sign-in-sign-out#top)を見て、それをパラゴンとして使用してください。 – icantbecool

0

この方法は、あなたが持っているパスワードロジックに依存します
validates :password, :length => { :minimum => 8, :maximum => 20}, :unless => Proc.new { |u| u.password_optional? or u.password.blank? } 
    validates :password, :confirmation => true, :unless => Proc.new { |u| u.password_optional? } 

...しかし、鉱山は次のようになります。

パスワードは、次の手順を実行し、オプションになりたい任意のアクションで
def password_optional? 
    optional = (encrypted_password.present? && password.blank? && password_changing.blank?) 
    optional 
    end 

ユーザーコントローラー

@user.password_optional = true 

(...あなたは@userオブジェクトを持っていると仮定すると)私はこれを仮定更新アクションになります。

+0

認証宝石を使用していない場合でも、パスワードを確認せずにユーザーの編集を完了できますか? – Elias7

+0

はい、どうしてですか?パスワードが空白であるかどうかを確認し、update_attributesの前にそのタイプのチェックをしないでください。 –

+0

パスワードが正しく入力されているかどうかを確認しようとしていますか? –

0

は私が今働いているプロジェクトでそれを行う方法です:

Userモデル:あなたが宝石を工夫使用している場合は、あなたのUserモデルでこれを入れて

関連する問題