だから、それはどのようにこれはなぜ存在するのですか?
@article.authors.exists?
が真実であることが可能であり、かつ
@article.authors.empty?
も真である????私は質問を読み違える - これはあなたが探している答えではありません
def new
@article = Article.new
# @article.build.authors unless @article.authors.exists?
# @article.build.authors if @article.authors.empty?
end
と
class Article < ActiveRecord::Base
has_many :authors
accepts_nested_attributes_for :authors
end
'@ article'オブジェクトからすべての作者を削除したが、あなたの変更をデータベースにコミットしていない可能性があります(' exists? 'は' true'を返します)?この結果の文脈は提供していません。 –
返事ありがとうございましたJeremy、質問を更新しました。 – pingu
私はあなたのコードを再作成しました。この状態では、 '@ article.authors.exists?'は 'false'を返し、' @ article.authors.empty? 'は' true'を返します。 –