私は次のものを持っています:
def User
has_and_belongs_to_many: :following, class: "User", inverse: :followers
has_and_belongs_to_many: :followers, class: "User", inverse: :following
end
UserはDeviseオブジェクトでもあることに注意してください。これは、ユーザーを保存するときに、保存するために:passwordと:password_confirmationが必要であることを意味します。
Deviseを使用するRailsアプリのコンテキストで、現在サインインしているユーザーであるcurrent_userにアクセスできます。
following_user = User.find(following_id)
current_user.following.push(following_user)
「current_user」は認証されているため正常に保存されますが、following_userは:passwordと:password_confirmationの欠落の検証に失敗するため保存されません。
とにかく、逆オブジェクトの検証を無効にできることはありますか?
逆の両側に「validate:false」を追加してみましたが、違いはありませんでした。(この場合の検証オプションを理解しましたか?)
このシナリオに対処するための推奨されるアプローチは何ですか?ありがとう。