Skip to content

Instantly share code, notes, and snippets.

@alfredorico
Last active October 22, 2023 21:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfredorico/70cfd746577ca62fafa12737294cd28a to your computer and use it in GitHub Desktop.
Save alfredorico/70cfd746577ca62fafa12737294cd28a to your computer and use it in GitHub Desktop.

Run the following command to generate a new rails app without any ruby installation in the host machine. it just needs Docker.

export APP_NAME=myapp ; docker run --rm -v ${PWD}:/$APP_NAME -w /$APP_NAME -t ruby:slim \
sh -c "apt update && apt install -y --no-install-recommends git build-essential libpq-dev\
&& gem install -N rails -v '~>7' \
&& rails new $APP_NAME --database=postgresql --skip-system-test --skip-test \
&& chown -R $(id -u):$(id -g) $APP_NAME/"

Because I'm running this command in Manjaro Linux, I need to chown the generated files to my linux user host otherwise the owner would be root and wouldn't be able to do any changes. This chown command is not needed in MacOS.

The workdir path can define the rails application name. Hence with the above command, if we were generated the rails app with the command rails new . --database= ... you'll get app name from the parent folder and you can confirm that checking the config/application.rb file:

image

We're skiping the rails default testing becuase usually we setup RSpec as the testing framework

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment