gpt4 book ai didi

ruby-on-rails - Rails 模型 - NameError : uninitialized constant

转载 作者:数据小太阳 更新时间:2023-10-29 08:43:44 26 4
gpt4 key购买 nike

我有两个模型:

app/models/data_science/field_of_studies_job_titles.rb

module DataScience
class FieldOfStudiesJobTitle < ActiveRecord::Base
self.table_name = 'ds_campus_transitions_disciplines_current'
self.primary_keys = :fieldofstudy, :jobrole
end
end

app/models/field_of_studies_job_title.rb

class FieldOfStudiesJobTitle < ActiveRecord::Base
belongs_to :job_title
belongs_to :field_of_study

validates :job_title_id, uniqueness: { scope: :field_of_study_id }

def self.import(source)
source.find_in_batches do |batch|
batch.each do |item|
puts "huhu"
end
end
end

rails console 中:

bundle exec rails c
Loading development environment (Rails 4.2.7)
irb(main):001:0> FieldOfStudiesJobTitle.import(::DataScience::FieldOfStudiesJobTitle)
NameError: uninitialized constant DataScience::FieldOfStudiesJobTitle
from (irb):1
from /usr/local/bundle/gems/railties-4.2.7/lib/rails/commands/console.rb:110:in `start'
from /usr/local/bundle/gems/railties-4.2.7/lib/rails/commands/console.rb:9:in `start'
from /usr/local/bundle/gems/railties-4.2.7/lib/rails/commands/commands_tasks.rb:68:in `console'
from /usr/local/bundle/gems/railties-4.2.7/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /usr/local/bundle/gems/railties-4.2.7/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
irb(main):002:0>

为什么我会收到此错误消息?

我知道当 Rails 环境没有加载调用该方法的类的文件时会发生这种情况。

但为什么会发生在这种特殊情况下?

最佳答案

您的文件名在 field_of_studies_job_titles 末尾有一个 s

关于ruby-on-rails - Rails 模型 - NameError : uninitialized constant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39350881/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com