简体   繁体   English

Docker compose 的 Rails 控制台问题

[英]Rails console issue with Docker compose

I have created a rails app with a pgsql database using DockerCompose.我使用 DockerCompose 创建了一个带有 pgsql 数据库的 rails 应用程序。 It seems to work fine but I have issues with using the rails console while running the app.它似乎工作正常,但我在运行应用程序时使用 rails 控制台有问题。 What I do is :我做的是:

  • docker-compose up . docker-compose up The app starts running.应用程序开始运行。
  • Then I run : docker exec -it ID_OF_RAILS_CONTAINER bin/rails console , or " docker-compose run CONTAINER_NAME rails console " (I tried both)然后我运行: docker exec -it ID_OF_RAILS_CONTAINER bin/rails console ,或“ docker exec -it ID_OF_RAILS_CONTAINER bin/rails console -compose run CONTAINER_NAME rails console ”(我都试过)

The console opens with this :控制台打开如下:

Creating transcendance_backend_run ... done
Running via Spring preloader in process 21
Loading development environment (Rails 6.0.3.4)
irb(main):001:0>

Then when I try to create a model, I get the following error:然后,当我尝试创建模型时,出现以下错误:

irb(main):001:0> rails g model user name guild_id banned
Traceback (most recent call last):
        1: from (irb):1
NameError (undefined local variable or method `banned' for main:Object)

Whatever I type, I get this error.无论我输入什么,我都会收到此错误。

I have tried commenting " gem 'spring-watcher-listen', '~> 2.0.0' " in my gemfile, but now the console just hangs forever when I try to generate a model.我曾尝试在我的 gemfile 中评论“ gem 'spring-watcher-listen', '~> 2.0.0' ”,但是现在当我尝试生成模型时,控制台会永远挂起。

Does anyone know how to fix this?有谁知道如何解决这一问题?

Thank you谢谢

generate is a Rake task bundled with Rails. generate是一个与 Rails 捆绑在一起的 Rake 任务。 You can run it in the container like this您可以像这样在容器中运行它

docker exec -it ID_OF_RAILS_CONTAINER bin/rails model user name guild_id banned

However, unless the container file system is configured to do a two-way sync with your local, it's likely that the files generated won't appear on you local machine.但是,除非容器文件系统配置为与本地进行双向同步,否则生成的文件很可能不会出现在本地计算机上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM