0

サインイン/サインアップと、has_secure_passwordおよびauthenticateメソッドを使用したセッションを設定した後、電子メールによる確認を行いたい。ユーザーモデルがあり、確認済みのブール値を追加しました。ユーザーが作成されたら、確認済みのブール値をfalseに設定し、リンクを記載したメールを送信します。リンクをクリックすると、/ users /:id / confirmへのGETリクエストが生成され、users_controllerで次の「confirm」アクションのコードが実行されます。


def confirm
    @user = User.find(params[:id])
    @user.update_attributes(confirmed: true)
    if @user.save 
      sign_in(@user)
      flash[:success] = "Your account has been successfully confirmed"
    else
      flash[:error] = "There has been a problem confirming your account "
    end 
     redirect_to root_path
  end

非常に単純です(後で検証トークンを実行します)。私の問題は、私のユーザーが決して保存されないことです。

@user.errors.full_messages
戻り値 :

["Password is too short", "Password confirmation can't be blank"]

毎回パスワードを編集せずにユーザーオブジェクトを変更するにはどうすればよいですか?どんな助けでも大歓迎です。

ありがとう !

4

1 に答える 1

1

update_attributesの代わりにupdate_attributeを使用してみてください。

  @user.update_attribute(:confirmed, true)
于 2012-07-08T20:01:17.983 に答える