【问题标题】:No Method Error: undefined method `find_each' for User:Class没有方法错误:用户:类的未定义方法“find_each”
【发布时间】:2017-08-21 19:05:21
【问题描述】:

我编写了一个调度程序函数,它会自动检查用户的免费试用是否已结束,然后自动将其升级为付费订阅。问题是当我尝试从命令行运行任务时出现以下错误:

无方法错误:用户:类的未定义方法“find_each”

task :process_trial_accounts => :environment do
  puts "Processing Trial Users"
   User.find_each do |user|

plan_id  = MailFunnelsUser.get_user_plan(user.client_id)
if plan_id == -99

  products = Infusionsoft.data_query('SubscriptionPlan', 100, 0, {}, [:Id, :PlanPrice])

  product = products.select { |product| product['Id'] == 2 }[0]

  unless product

  end

  price = product['PlanPrice']

  cardId = 0
  current_year = Date.today.strftime('%Y')
  current_month = Date.today.strftime('%m')
  creditCardId = Infusionsoft.data_query('CreditCard',
                                         100,
                                         0,
                                         {'ContactId' => user.clientid, 'ExpirationYear' => '~>=~' + current_year, 'Status' => 3},
                                         [:Id, :ContactId, :ExpirationMonth, :ExpirationYear]
  ).each do |creditCard|

    if Integer(creditCard['ExpirationYear']) == Integer(current_year)
      if Integer(creditCard['ExpirationMonth']) >= Integer(current_month)

        cardId = creditCard['Id']
      end
    else

      cardId = creditCard['Id']
    end
  end

  if cardId != 0

    subscription_id = Infusionsoft.invoice_add_recurring_order(user.clientid, true, 2, 4, cardId, 0, 0)


    invoice_id = Infusionsoft.invoice_create_invoice_for_recurring(subscription_id)

    upgrade_response = Infusionsoft.invoice_charge_invoice(invoice_id, "Automatic Upgrade to 1000 Subscriber Tier", cardId, 4, false)

    if upgrade_response[:Successful]
      # Tag for 1000 sub tier level plan
      new_tier_level_tag = 106

      # Tags to remove from user
      trial_ended_tag = 145
      failed_payment_tag = 120

      # Remove Tags from user for failed payment and Trial ended
      Infusionsoft.contact_remove_from_group(user.clientid, trial_ended_tag)
      Infusionsoft.contact_remove_from_group(user.clientid, failed_payment_tag)


      # Add tag to user for 1000 subscribers tier level
      Infusionsoft.contact_add_to_group(user.clientid, new_tier_level_tag)


    end

  end

else
  next
end

 end





end

我的应用程序托管在 heroku 上,我正试图通过那里运行这项工作。任何帮助表示赞赏!谢谢!

【问题讨论】:

  • find_each 方法是ActiveRecord 方法,所以你的 User 类必须继承自 ActiveRecord。你确定你使用这个 ORM 吗?
  • 请提供用户类代码。

标签: ruby-on-rails ruby heroku


【解决方案1】:

find_each方法是ActiveRecord方法,这意味着User类必须继承自ActiveRecord。如果您不使用这种 ORM,则不能使用find_each

如果您提供 User 类代码库会容易得多。

干杯

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2021-08-02
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多