我正在尝试运行一个rake任务,但是遇到了错误 NameError: uninitialized constant User。
我正在尝试运行一个rake任务,但是遇到了错误 NameError: uninitialized constant User。
我正在尝试运行一个rake任务来添加到我的数据库。然而,我遇到了下面的错误。如果有人遇到过这个错误或知道解决方法,任何帮助将不胜感激!\n
rails中止! NameError: 未初始化常量User /Users/richardbatt/Desktop/Ruby/NelsonParksProject/lib/tasks/users.rake:31:in `block (3 levels) in' /Users/richardbatt/Desktop/Ruby/NelsonParksProject/lib/tasks/users.rake:22:in `each' /Users/richardbatt/Desktop/Ruby/NelsonParksProject/lib/tasks/users.rake:22:in `block (2 levels) in ' /Users/richardbatt/Desktop/Ruby/NelsonParksProject/bin/rails:4:in ` ' Tasks: TOP => users:xero_users (通过使用--trace运行任务查看完整跟踪)
\n
namespace :users do desc "从Xero获取用户" task :xero_users do require 'xero-ruby' creds = { client_id: '...', client_secret: '...', grant_type: 'client_credentials' } xero_client = XeroRuby::ApiClient.new(credentials: creds) @token_set = xero_client.get_client_credentials_token # 保存@token_set accessToken = @token_set["access_token"] users = xero_client.accounting_api.get_users('').users users.each do |user| userID = user.user_id userEmailAddress = user.email_address userFirstName = user.first_name userLastName = user.last_name userIsSubscriber = user.is_subscriber userOrganisationRole = user.organisation_role User.create(email: userEmailAddress) end end end
\n我试图将新用户添加到我的数据库中。当我在我的主控制器中使用\'User.create(email: \"test\")\'时,它会添加到数据库中。只是当我运行rake任务时不会添加。\n谢谢!