我正在尝试使用Rails控制台遍历所有Ad
模型。我想每个广告进行所谓extract_targets
的私有方法:Rails NoMethodError:私有方法上的私有方法?
Ad.all.each do |ad|
ad.extract_targets
end
虽然当我得到以下错误,而循环:
NoMethodError: private method `extract_targets' called for #<Ad:0x000000071123b0>
这是一个私有方法,但我从每个调用它广告,所以我不知道为什么会引发异常?
private
def extract_targets
normal_name = campaign.name.sub(/^www\./, '')
links = page.css('a').map { |link| URI(link['href']) }.select {|link| link.host.sub(/^www\./, '').end_with? normal_name }
location = links.first.path
location = '/' if location.empty?
location.normalize_path!
update_column :target_id, campaign.targets.find_or_create_by(location: location).id
end
私有方法只能从类 –
@DeepakMahakale内部调用:即使如此,并非总是如此。 –