我该如何解决将Rails应用程序部署到Heroku的麻烦?

时间:2018-11-17 18:51:18

标签: ruby-on-rails ruby heroku

我无法将Rails应用程序部署到Heroku

当我尝试将项目推送到Heroku( git push heroku master )时,它给了我这个错误:

[JsonObject(MemberSerialization.OptOut)]
public class UserModel
{
    public UserModel()
    {

    }
    public UserModel(string firstName, string lastName, int age, string address)
    {
        this.Address = address;
        this.Age = age;
        this.FirstName = firstName;
        this.LastName = lastName;
    }

    public void ConvertDto(UserDto userDto)
    {
        ID = userDto.ID;
        FirstName = userDto.FirstName;
        LastName = userDto.LastName;
        Age = userDto.Age;
        Address = userDto.Address;
    }

    public int ID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int Age { get; set; }
    public string Address { get; set; }
    }

但是我更改了红宝石版本以适合heroku 18。

我在https://devcenter.heroku.com/articles/ruby-support#supported-runtimes处搜索了当前兼容的红宝石版本

我安装了rvm install“ ruby​​-2.5.3”

我在应用程序的Gemfile中添加了ruby'2.5.3'行

我确实运行了捆绑安装程序(无错误消息)

最后,我确实运行了git push heroku master

这是我的Gemfile

Counting objects: 300, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (269/269), done.
Writing objects: 100% (300/300), 255.34 KiB | 6.08 MiB/s, done.
Total 300 (delta 73), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote:  !     Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
remote:             Detected buildpacks: Ruby,Node.js
remote:             See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote:        Command: 'set -o pipefail; curl -L --fail --retry 5 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-18/ruby-2.3.5.tgz -s -o - | tar zxf - ' failed on attempt 1 of 3.
remote:        Command: 'set -o pipefail; curl -L --fail --retry 5 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-18/ruby-2.3.5.tgz -s -o - | tar zxf - ' failed on attempt 2 of 3.
remote: 
remote:  !
remote:  !     An error occurred while installing ruby-2.3.5
remote:  !     
remote:  !     This version of Ruby is not available on Heroku-18. The minimum supported version
remote:  !     of Ruby on the Heroku-18 stack can found at:
remote:  !     
remote:  !     https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to agora-challenge.
remote: 
To https://git.heroku.com/agora-challenge.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/agora-challenge.git'

我看到了类似的问题:Having Trouble to deploy a Rails App to Heroku,但答案建议转到与上面相同的链接...

谢谢!

3 个答案:

答案 0 :(得分:0)

您应该有一个Salesforce CLI文件,其中包含.ruby-version

答案 1 :(得分:0)

我发布的解决方案可能会晚,但可以帮助其他人。 大多数人发布的解决方案要求升级红宝石版本。在应用程序中更新红宝石版本可能会花费一些时间。 但是使用以下解决方案,应用程序可以部署而无需更新ruby版本。

heroku当前使用的堆栈是heroku-18,具有Ubuntu 18.04的映像。它具有最低支持的运行时为ruby 2.4.5other information here

要在此Ruby版本以下运行复制,您需要为应用程序降级heroku堆栈。

打开控制台,然后运行heroku stack

  cedar-14
  container
  heroku-16
* heroku-18

您需要降级以支持您的Ruby版本的堆栈。对于ruby 2.3.x,您可以设置heroku-16

heroku stack:set heroku-16

现在,如果您运行heroku stack,将为您的应用程序找到heroku-16堆栈集。

  cedar-14
  container
* heroku-16
  heroku-18

您可能会在控制台Information here上遇到安全漏洞问题。

尝试仅将链轮宝石更新到最低3.7.2,例如:

bundle update sprockets --bundler '3.7.2'

或者您可以设置:

config.assets.compile = false # Disables security vulnerability

运行git push heroku master。繁荣!!您的应用程序已成功部署。

答案 2 :(得分:0)

请在此处检查每个堆栈(cedar 14,cedar 16和cedar 18)中安装的Ubuntu软件包。

https://devcenter.heroku.com/articles/stack-packages#installed-ubuntu-packages

在列表中搜索“ ruby​​”,然后为应用程序选择适当的雪松堆栈。

enter image description here

我希望这些信息可以对其他人有所帮助。