vendredi 18 novembre 2016

Rails not loading model.rb file

I don't know why, but for some reason my nested association is not being respected by rails.

My student class has nested associations: addresses, tests

The addresses association works fine. The tests association, which is identical to the addresses association, does not work....??

Here's the student model:

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

Here's the addresses model (which works):

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

And here's the (basically) identical tests model (which doesn't work):

class Test < ActiveRecord::Base
  belongs_to :student
  validates :name, length: {maximum: 40}

  def self.ransackable_attributes(auth_object = nil)
    ['score', 'date']
  end
end

I feel like I didn't create my model correctly or something, and Rails doesn't know it's there? It's completely ignoring the validation as well as the ransack function.

Aucun commentaire:

Enregistrer un commentaire