なぜか分かりませんが、何らかの理由でネストされた関連付けがレールによって尊重されていません。Railsがmodel.rbファイルをロードしていません
私の学生のクラスが入れ子になった団体:アドレスは、アドレスの関連付けが正常に動作します
テストします。アドレスの関連付けと同じテストの関連付けは機能しません。テストインスタンスを作成して編集することはできますが、モデルで定義されている検証チェックを受けず、モデルで指定した検索機能も実装していません。
はここで学生モデルだ:
class Student < ActiveRecord::Base
unloadable
validates :name, presence: true, length: {maximum: 50}
has_many :addresses, :dependent => :destroy
has_many :tests, :dependent => :destroy
accepts_nested_attributes_for :addresses,
:reject_if => :all_blank,
:allow_destroy => true
accepts_nested_attributes_for :tests,
:reject_if => :all_blank,
:allow_destroy => true
end
は、ここでのアドレスモデル(作品)です:
class Address < ActiveRecord::Base
belongs_to :student
validates :address, presence: true, length: {maximum: 80}
def self.ransackable_attributes(auth_object = nil)
['county', 'zip', 'address']
end
end
そして、ここでは(動作しない)(基本的に)同じテストモデルです:
class Test < ActiveRecord::Base
belongs_to :student
validates :name, length: {maximum: 40}
def self.ransackable_attributes(auth_object = nil)
['score', 'date']
end
end
これは検証とransack機能を完全に無視しています。すべてがエラーなく実行されますが、検証された長さを超えていても、必要な情報を入力できます。エラーメッセージも表示されません。
私のモデルを正しく作成したり、何かを作成したりしなかったような気がします。
*「うまくいかない」*を詳しく説明してください。例:エラーメッセージはありますか?何をしようとしましたか、何が起こったのでしょうか? – spickermann
私の編集を見て、一番下を詳しく説明します。 – ineedahero
私はあなたのアプリケーションでTestという名前の__another__モデル/クラスを持っていると確信しています。 –