小编cho*_*s24的帖子

我不明白“可选:true”在轨道上如何工作?

我不明白如何工作optional: true。它已经解决了必须存在的错误

\n

错误按摩

\n

我\xe2\x80\x99m通过rails安装了以下功能,由于验证,记录没有保存。\n我听说optional: true允许保存nil记录,但没有optional: true记录就没有保存'不过没有。当我尝试访问时发生错误relation#create

\n

我的代码在这里 \xe2\x86\x93

\n
class User < ApplicationRecord\n  # Include default devise modules. Others available are:\n  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable\n  devise :database_authenticatable, :registerable,\n         :recoverable, :rememberable, :validatable\n         \n  has_many :articles\n  has_many :goods\n  \n  has_many :active_relations, class_name: "Relation", foreign_key: :following_id\n  has_many :passive_rerations, class_name: "Relation", foreign_key: :follower_id\n  \n  has_many :followings, through: :active_relations, source: :follower\n  has_many :followers, through: :passive_rerations, source: :following\nend\n
Run Code Online (Sandbox Code Playgroud)\n
class Relation < ApplicationRecord\n …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails ruby-on-rails-5

3
推荐指数
1
解决办法
8044
查看次数

标签 统计

ruby ×1

ruby-on-rails ×1

ruby-on-rails-5 ×1