#わからないこと
現在railsチュートリアルを勉強しています。そこでassignsについて知りました。
Ruby on Rails チュートリアル
私はassignとは、作成したインスタンスのデータにアクセスする関数と理解しました。
その場合以下のコードを
ruby
1 test "should not allow the admin attribute to be edited via the web" do 2 log_in_as(@other_user) 3 assert_not @other_user.admin? 4 patch user_path(@other_user), params: { 5 user: { password: @other_user.password, 6 password_confirmation: @other_user.password, 7 admin: true } } 8 assert_not @other_user.reload.admin? 9 end
次のコードのように置き換えれるのではないかと思いました。
ruby
1 test "should not allow the admin attribute to be edited via the web" do 2 log_in_as(@other_user) 3 assert_not @other_user.admin? 4 patch user_path(@other_user), params: { 5 user: { password: assigns(:other_user).password, 6 password_confirmation: assigns(:other_user).password, 7 admin: true } } 8 assert_not @other_user.reload.admin? 9 end
しかし後者ではエラーが発生してしまいました。(前者は異常なし)
これは何故なのでしょうか。ご教授お願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/03/21 12:58
2020/03/21 13:01
2020/03/22 01:26