Check for the new ruby and rails versions
Here we are going to install Ruby – 2.5.1 & Rails – 5.2.0 (API only application)
Get rbenv into action
If you are not installed rbenv, you can install it from here:
After the installation make sure that, your $PATH has included rbenv/shims path. Else rbenv will not work.
1. $ rbenv install --list # Gets the list of ruby versions available $ rbenv install 2.5.1 ruby-build: definition not found: 2.5.1 The following versions contain `2.5.1' in the name: rbx-2.5.1 See all available versions with `rbenv install --list'. If the version you need is missing, try upgrading ruby-build: brew update && brew upgrade ruby-build
rbenv cannot find the version: 2.5.1
$ brew upgrade ruby-build --HEAD Now install ruby 2.5.1 $ rbenv install 2.5.1
Create a new gemset:
Rbenv gemset is a separate script and not coming with rbenv. If you are not installed this, you can install it from here:
$ rbenv gemset create 2.5.1 demo-app
That set up a directory for you in ~/.rbenv/versions/2.5.1/gemsets/demo-app
Set the ruby version to the newest
$ rbenv local 2.5.1 $ rbenv version => 2.5.1
- Activate New Gemset
For activating a gemset we need to create a .rbenv-gemsets file in the current directory.
$ touch .rbenv-gemsets $ echo demo-app > .rbenv-gemsets
Check active gemset:
$ rbenv gemset active
Install Rails 5.2.0 API only Application
$ gem install rails -v '5.2.0' $ rails -v Rails 5.2.0
Later we can delete this .rbenv-gemsets file and add a new file named ‘.ruby-gemset’ in the rails project directory. I cannot find any other option for doing this. If anyone know more about this, please give a comment. I appreciate that.
Create a New Rails app
$ rails new demo-app --api -T # API only skip the testing framework altogether
For Full Rails:
$ rails new demo-app -T -d postgresql # skip the testing framework altogether, uses Postgres Database
-T to exclude Minitest – the default testing framework if you are planning to use RSpec to test your API.
Rspec test framework:
You can use the following with Rspec.
Collection of testing matchers extracted from Shoulda (http://matchers.shoulda.io)
Strategies for cleaning databases in Ruby. Can be used to ensure a clean state for testing
A library for generating fake data such as names, addresses, and phone numbers.
use option: –no-rdoc –no-ri # skips the documentation
Remove Rbenv Gemset and add Ruby gems file
$ rm .rbenv-gemsets $ cd demo-app $ touch .ruby-gemset $ echo demo-app > .ruby-gemset
$ rails s => Booting Puma => Rails 5.2.0 application starting in development => Run `rails server -h` for more startup options Puma starting in single mode... * Version 3.11.4 (ruby 2.5.1-p57), codename: Love Song * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://0.0.0.0:3000 Use Ctrl-C to stop
Done! Lets go…