【问题标题】:why heroku can't run dev:fake_user?为什么 heroku 不能运行 dev:fake_user?
【发布时间】:2018-07-19 18:30:49
【问题描述】:

在rails中,我写了一个自动生成假用户的任务

task fake_user: :environment do
  User.destroy_all
  filelink = "" 
    Dir.glob("#{Rails.root}/public/avatar/admin.jpg").map do |pic|
      client = FilestackClient.new('ARz3g0HLfR5i0KuobcdJmz')
      filelink = client.upload(filepath: pic)
  end    
  admin = User.create(
      email: "admin@example.com",
      password: "admin123", 
      role: 'admin', 
      name: 'admin',
      introduction: FFaker::Lorem::sentence(30), 
      avatar: filelink.url
    )
  puts admin.name
  20.times do |i|
    name = FFaker::Name::first_name
    filelink = "" 
    Dir.glob("#{Rails.root}/public/avatar/user#{i+1}.jpg").map do |pic|
      client = FilestackClient.new('ARz3g0HLfR5i0KuobcdJmz')
      filelink = client.upload(filepath: pic)
    end            

    user = User.create(
      name: name,
      email: "#{name}@example.co",
      password: "12345678",
      introduction: FFaker::Lorem::sentence(30),                
      avatar: filelink.url      
    )

    user.save!
    puts user.name

  end
end

并且在本地运行时没有错误。

但是当我将它部署到 Heroku 时,发生了一些错误

这是我做的步骤

  1. Heroku run bundle install(正确)
  2. Heroku run rails db:migrate(正确)
  3. Heroku run rails dev:fake_user(错误...)

这是我收到的错误消息

希望有人能帮我解决这个问题....谢谢....

【问题讨论】:

    标签: ruby-on-rails heroku filestack


    【解决方案1】:

    从日志看来,您的连接已断开。您是否尝试过在 database.yml 中关注? reconnect: true

    【讨论】:

    • 您的意思是在生产中添加 'reconnect: true':?
    猜你喜欢
    • 2021-01-28
    • 2015-04-07
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    • 2019-03-21
    • 2012-09-01
    • 1970-01-01
    • 2021-09-12
    相关资源
    最近更新 更多