0
ところ、多くのイベントを持つユーザー:レール - accepts_nested_attributes_forと存在検証、私は単純な関係を持っている私のアプリケーションで
class User < ApplicationRecord
has_many :events, foreign_key: 'created_by', dependent: :destroy
accepts_nested_attributes_for :events
end
class Event < ApplicationRecord
belongs_to :user, foreign_key: 'created_by', inverse_of: :events
validates :created_by, presence: true
end
私は私はいくつかのイベントで一緒にユーザーを作成しようとしています検証エラーが発生する"Companies.created byは空白にできません"。
私のparamsハッシュは、以下のようになります。
{"user"=>{"events_attributes"=>[{"name"=>"disney show"}]}}
私は予想通りvalidates :created_by, presence: true
すべての作品取り除きます。どんな助けもありがとう! inverse_of:
を使用して、Userモデルに明示的に双方向の関連を指定する
このフォームをレンダリングする場所からコントローラ機能を追加します。 – Satendra