我是Ruby的新手(不到6个月的经验),我正在尝试检查model.rb
文件中的方法何时运行。我以为每次实例化一个新模型时它都会一直运行,但是显然不是。至少它没有运行。
我什至放了一些binding.pry
来停止运行,但是它并没有停止创建模型,这意味着没有调用方法trails_available
,对吗?
def trails_available= value
binding.pry
self.db_trails_available = value
end
def trails_available
binding.pry
if self.db_trails_available
unless self.db_trails_available.empty?
self.db_trails_available
else
trails_available = Trail.available(0,self.id).pluck(:id)
self.update_attribute(:db_trails_available, trails_available)
trails_available
end
end
end
模型的文件名为company_profile.rb
,当我实例化新的公司资料时,变量db_trails_available
返回了一个空白数组“ []”。见下文:
<CompanyProfile:0x0000001161e908
id: 232,
company_id: 13,
access_type: "test_7",
blocked_trails_ids: [nil, 68],
deleted_at: nil,
created_at: Wed, 25 Sep 2019 12:40:42 -03 -03:00,
updated_at: Wed, 25 Sep 2019 12:40:42 -03 -03:00,
blocked_components_ids: [nil, 170],
blocked_materials_ids: [nil, 723],
school_id: 13,
available_minutes: nil,
blocked_academies_ids: [nil, 1],
db_trails_available: [],
db_components_available: [],
db_materials_available: [],
top_components: [],
optional_materials_ids: [nil, 723],
optional_components_ids: [nil, 170],
optional_trails_ids: [nil, 68],
skip: true>
trails_available
运行时我要抽出什么错?