Generate an application with a specific Rails version
Generate an application with a specific Rails version

There are few ways we can create an application with specific rails version.
In this article, we will create a new rails app of version 6.0.1 while our system may have multiple rails versions installed in our system.
Here is the list of rails versions that were already installed in my system while writing this article.
rails (6.0.2.2, 6.0.2.1, 6.0.1)Method 1: Common method
Let’s start with most common and widely documented method:
rails version new app_nameCode example:
Let’s create an app named my_app with rails version 6.0.1.
gem install rails -v 6.0.1 #only when the gem has not been installed in the desired ruby version you are using
rails _6.0.1_ new my_appThe
_6.0.1_feature is provided byRubyGems. It checks if the first argument(ARGVArray) is a version. It then modifies the $LOAD_PATH accordingly. Ruby seeks help fromRubyGemsbecause it knows where the gems are stored.
Method 2: Let bundler handle the rails version
In this method we will let bundler handle rails version.
Our workflow if we wanted to setup new project with rails version 6.0.1 would be:
2.1: Make new folder and initialize bundler
# make directory for new rails app
mkdir my_app
cd my_app
# specify ruby version we want to use
echo 2.4.1 > .ruby-version
# initialise bundler (creates Gemfile)
bundler init2.2: Specify rails version
At this stage, our Gemfile probably looks like this:
# A sample Gemfile
source "https://rubygems.org"
# gem "rails"We have to uncomment rails gem and specify version so that our Gemfile looks like this:
# A sample Gemfile
source "https://rubygems.org"
gem "rails", '6.0.1'Now we need to run bundle install. (This would install rails 6.0.1 if it had not been installed yet).
2.3: Initialise new rails app with specified rails version
At this point we already have minimal project with rails version 6.0.1.
Now, we can use the rails command line tool with bundle exec to force the version:
bundle exec rails new . --force # --force to overrite curent GemfileIf you were unaware about rails runtime option force, it is used to overwrite files that already exist. Just type rails in your commandline and you will see explanation about this command.
Now, we have new rails project with our desired rails version(6.0.1).
What do you think about this flow of setting up version specific new rails project? Feel free to comment.
Happy learning!
References:
Keep reading

Fix mise GitHub Rate Limit with a Token
mise makes unauthenticated GitHub API calls by default. When you hit the rate limit installing tools, a personal access token (no scopes required) fixes it permanently.

How to solve Deployment Failure-`assets:precompile`
I was trying to deploy rails 6 app on ec2 server using capistrano when precompile failure lead to whole deploymentt failure. I had to uninstall cmdtest and install yarn

How to Sort an Array of Objects in JavaScript
How to Sort an Array of Objects in JavaScript

What did you take away?
Thoughts, pushback, or a story of your own? Drop a reply below — I read every one.
Comments are powered by Disqus. By posting you agree to theirterms.