Install Rails 5.2.0 API Only application with latest Ruby 2.5.1

Check for the new ruby and rails versions
https://www.ruby-lang.org/en/downloads/
https://rubygems.org/gems/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:
https://github.com/rbenv/rbenv
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

Oops..!

rbenv cannot find the version: 2.5.1

Upgrade ruby-build

Mac OSX:

$ 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:
https://github.com/jf/rbenv-gemset

$ 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 # skips the documentation

-T to exclude Minitest – the default testing framework if you are planning to use RSpec to test your API.

Rspec test framework:
https://github.com/rspec/rspec-rails

You can use the following with Rspec.
Shoulda Matchers:
Collection of testing matchers extracted from Shoulda (http://matchers.shoulda.io)
https://github.com/thoughtbot/shoulda-matchers

Database Cleaner:
Strategies for cleaning databases in Ruby. Can be used to ensure a clean state for testing
https://github.com/DatabaseCleaner/database_cleaner

Faker:
A library for generating fake data such as names, addresses, and phone numbers.
https://github.com/stympy/faker

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

Goto http://localhost:3000/

rails-5.2.api-application

Done! Lets go…

Advertisements

Install Learning Locker (NodeJS) in your Mac OSX

Visit the following link to install LL on CentOS, Fedora, Ubuntu, and Debian OS
http://docs.learninglocker.net/guides-installing/

Mac OS is not supported in the installation process specified above.

You can install Learning Locker in Mac OSX by custom installation.

Steps to Install LL in Mac OSX:

1. Clone the repo from learning locker git repo

$ git clone https://github.com/LearningLocker/learninglocker.git

Enter into the directory and install the requirements:

$ yarn install

You can be built 5 distinct services with this codebase.
2. Install services

If you want to install all services on the same machine, you can use the following one command:
$ yarn build-all

Install Services separately if you want to install each service in different servers

Install the UI Server  
$ yarn build-ui-server

Install the UI Client
$ yarn build-ui-client

Install the API Server
$ yarn build-api-server

Install the Worker
$ yarn build-worker-server

Install CLI
$ yarn build-cli-server

Note: Copy the .env.example into a new .env file and edit as required

RUNNING THE SERVICES VIA PM2

Install pm2 , if you have not yet installed
$ npm i -g pm2

To start API, Scheduler, UI, Worker services, navigate to the LL working directory and run:

$ pm2 start pm2/all.json

INSTALLING THE XAPI SERVICE

Step 1: Clone the repo
$ git clone https://github.com/LearningLocker/xapi-service.git

Step 2: Enter into the directory and install the requirements and build

$ yarn install
$ yarn build

Note: Copy the .env.example into a new .env file and edit as required

To start the xAPI service, navigate to the xAPI Service working directory and run:

$ pm2 start pm2/xapi.json

You can check the service status:

$ pm2 status

$ pm2 restart all # restart all services

$ pm2 logs # view logs

Launch the UI:
http://localhost:3310/login, note that I have change the UI port in .env to 3310, as other services running in default port

TheLearningLockerMac

Now you have to create User for logging in. Lets create an Admin User by the following command.

$ node cli/dist/server createSiteAdmin [email] [organisation] [password]

In order to use this command you have to install the CLI server for LL, that I already mentioned in the installation steps.

An Admin Example
$ node cli/dist/server createSiteAdmin "MyEmailId" "CoMakeIT" “myPassword”

You can run the migrations by the following command if any pending migrations exists

$ node cli/dist/server migrateMongo

Now try to Login with the credentials.
LL-sign-in-error
Ooops… there is an issue, and we can’t login

After doing some research I found the issue. We need to add a secret key base to our Application to work with JWT tokens.
Open .env file and find:

# Unique string used for hashing
# Recommended length, 256 bits
APP_SECRET=

Create a 256 bit length hash key and give as a value. As I am a Rails developer, It is easy for me to create one by going into any my Rails project and type

$ rake secret

I get One! 🙂

Or you can use some online applications like: https://randomkeygen.com/

And do:
$ pm2 restart all

from LL project folder

Try to sign in again
LL-dashboard

Wohh, Its done. Great. Now you can try some bit of dashboard items like Graphs etc. Go on.

Laravel – PHP web framework Vs Rails, Installation

Laravel is a php web framework which following the model–view–controller (MVC) architectural pattern. It is gaining more and more popularity nowadays.

It is almost followed Ruby on Rails framework pattern, not only for MVC structure but also for the pattern that Rails adopt for doing various tasks. It uses composer that installs the software snippets you needed to achieve a particular task as Rails does it with bundler to pick gems.

The drawback of Laravel is it cannot achieve the power of Ruby like metaprogramming through php. So I need to write some more code in Laravel and its actually feels irritating if you want to write less code without the same repetitive patterns and keep it DRY.

Get and install composer

Goto (https://getcomposer.org/) Click download.

Run the following:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

This will install ‘composer.phar ‘ in the current directory.

Move that to bin folder to get it globally available as a command and rename it to composer

$ mv composer.phar /usr/local/bin/composer

Open new tab and Type

$ composer

Install Lareval

Using composer

$ composer create-project --prefer-dist laravel/laravel blog "5.4.*"

From laravel/laravel github repo OR via larval installer

$ laravel new blog
-bash: laravel: command not found

Install it:

$ composer global require "laravel/installer"

this makes it globally accessible

Make sure to place the $HOME/.composer/vendor/bin directory (or the equivalent directory for your OS) in your $PATH so the laravel executable can be located by your system.

Open ~/.bash_profile OR ~/.bashrc in Mac

and add the following line:

export PATH="$PATH:$HOME/.composer/vendor/bin"

save and exit

Open New tab type:

$ laravel
Laravel Installer 1.4.1
Usage:
  command [options] [arguments]

Check Laravel version:

$ php artisan --version
Laravel Framework 5.4.27

You are ready to go!