[英]Problem deploying Ruby on Rails 7 app on Heroku
I am trying to deploy my project to Heroku and I have this error:我正在尝试将我的项目部署到 Heroku 并且出现此错误:
Running: rake assets:precompile rake aborted: SyntaxError. /tmp/build_c99702b3/config/environments/production:rb:22, syntax error, unexpected constant. expecting 'do' or '{' or '('..:oku config:set RAILS_MASTER_KEY=ENV['RAILS_MASTER_KEY']
Although I have seen very similar errors and problems described here, nothing is working for me.尽管我看到了此处描述的非常相似的错误和问题,但对我没有任何帮助。 I have
credentials.yml.enc
file and master.key
file.我有
credentials.yml.enc
文件和master.key
文件。 Everything is working fine on localhost:3000,but when I try to deploy it I received this error.在 localhost:3000 上一切正常,但是当我尝试部署它时,我收到了这个错误。 I am running VMWare VM Ubuntu 22.04 LTS (although I have run it as well on 20.04 LTS) on Windows 10 machine.
我在 Windows 10 机器上运行 VMWare VM Ubuntu 22.04 LTS(尽管我也在 20.04 LTS 上运行过它)。 Here is my Gemfile:
这是我的 Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.1.1'
gem 'rails', '~> 7.0.3'
gem 'sprockets-rails'
gem 'pg', '~> 1.1'
gem 'puma', '~> 5.0'
gem 'importmap-rails'
gem 'turbo-rails'
gem 'stimulus-rails'
gem 'tailwindcss-rails'
gem 'jbuilder'
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
gem 'bootsnap', require: false
gem 'devise', '~> 4.7'
gem 'finnhub_ruby', '~> 1.1.16'
gem 'dotenv-rails', groups: %i[development test]
group :development, :test do
gem 'debug', platforms: %i[mri mingw x64_mingw]
%w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib|
gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'main'
end
end
group :development do
gem 'web-console'
end
I also try to use .env
file and had my master key defined there as well like this:我也尝试使用
.env
文件并在那里定义了我的主密钥,如下所示:
ENV['RAILS_MASTER_KEY'] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxx'
but it did not help as well.但这也无济于事。
Could you, please, let me know what is the problem and if somebody could provide detailed instructions on how to do this, I mean especially where and how the master key has to be placed, so it could deploy to Heroku?请您让我知道问题出在哪里,如果有人可以提供有关如何执行此操作的详细说明,我的意思是特别是必须将主密钥放置在何处以及如何放置,以便它可以部署到 Heroku? Thanks in advance for your answers.
提前感谢您的回答。
heroku config:set
is CLI command, you don't need to put this line to your production.rb
heroku config:set
是 CLI 命令,你不需要把这一行放到你的production.rb
If you need to set this env variable to Heroku just execute in your terminal after heroku create
command and before deploy如果您需要将此环境变量设置为 Heroku 只需在
heroku create
命令之后和部署之前在终端中执行
heroku config:set RAILS_MASTER_KEY=`cat config/master.key`
or或者
heroku config:set RAILS_MASTER_KEY="$(< config/master.key)"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.