09 May

How to use a specific version of Rails


Hi, this week I will cover how you can use a specific version of Rails should you need it.


If you call rails new, you will use the version of Rails you have installed on your system, but you might work with multiple versions of Rails and want to use a specific one for your new project, or you want to experiment with something with a given version. Experimenting is my most often use case. When fiddling with security issues, I usually generate a Rails app with the affected version.


To generate an app with a specific version, you can pass the version surrounded by underscores to rails new for the first parameter:

38e3f5e5-2e94-4cbd-bb4f-8798d84d6cc4.png 30.6 KB

This will generate a Rails 6.0.0 application.


If you would want to generate a Rails app with the Rails main repository, you can do that easily too:

e17d2d2b-a4e9-433b-878a-16e7a231f357.png 16.4 KB

If you don’t need an actual Rails app with the whole file structure, you could also use the Rails bug report templates. There is a separate one for various parts of Rails and also a generic one. They all come with an example test if you are testing buggy behavior.


You can also quickly create a single-file Rails app as I described here: A single-file Rails application, but only for experimenting, it is highly not recommended to use that for a real-world project.


That’s it for the week!