How to use a specific version of Rails - Rails Tricks Issue 6
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:
$ rails _6.0.0_ new rails6_test --database postgresql
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:
$ rails new rails_edge --main
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!
Did you enjoy reading this? Sign up to the Rails Tricks newsletter for more content like this!
Or follow me on Twitter
I run an indie startup providing vulnerability scanning for your Ruby on Rails app.It is free to use at the moment, and I am grateful for any feedback about it.
If you would like to give it a spin, you can do it here: Vulnerability Scanning for your Ruby on Rails app!