私はRails 5.0.0を使用しますが、何らかの理由でbelongs_to_required_by_default
が動作しません!Rails 5 belongs_to_required_by_default does not work
アプリケーションは、それがoptional: false
オプション
class Visit < ApplicationRecord
belongs_to :user, optional: false
end
> v = Visit.new
> v.valid? # => false
でのみ動作しますが、なぜ設定は動作しません。新しいレールとして5アプリ
class Visit < ApplicationRecord
belongs_to :user
end
> v = Visit.new
> v.valid? # => true
を作成しました:任意のための
Rails.application.config.active_record.belongs_to_required_by_default = true
感謝を提案
デフォルトで 'my_app/config/initializers/new_framework_defaults.rb' –
を' class Application
Ropeney
これはあなたの答えとして機能しますが、なぜイニシャライザフォルダから初期化されないのですか?理解できません。 –