Tuesday, July 24, 2018

How to install Ruby 2.X and Rails 5.X using RVM

The best way to install Ruby on Rails is using RVM in Linux.

Advantages of RVM,
1. You can shift between multiple versions of Ruby easily.
2. You don't have to worry about install Ruby dependencies. RVM install will take care of installing them. Some of the ruby dependencies are : gawk, autoconf, automake, bison, libffi-dev, libgdbm-dev, libncurses5-dev, libsqlite3-dev, libtool, libyaml-dev, pkg-config, sqlite3, zlib1g-dev, libgmp-dev, libreadline6-dev, libssl-dev
3. Easily upgrade Ruby version and try out a latest version to make sure your project works with the latest Ruby. If something breaks, changing the version is easy.
4. Delete unwanted Ruby version anytime :)

Installation steps.

Step 1. Install RVM

Source : https://rvm.io/rvm/install
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

\curl -sSL https://get.rvm.io | bash -s stable
$ source /etc/profile
$ source ~/.rvm/scripts/rvm
$ type rvm | head -n 1  (this command returns 'rvm is a function' )

Step 2. Install Ruby

To List all known Ruby versions by rvm

$ rvm list known
From the list, pick a version and install ruby

$ rvm install ruby-2.3.7

Step 3. Install Rails

Rails is a Ruby gem. I always install bundler gem along with rails installation because it will be used in all Rails application to install dependencies
$ gem install bundler
$ gem install rails

Step 4. check version and start a project

# To check the Ruby version
$ ruby -v

# to check the Rails version
$ rails -v

# to start a new rails project with Mysql database. Rails by default uses sqlite. If you want to use any other database you will have to specify the adapter in config/database.yml
$ rails new project_name -d mysql

# Go inside the new project 
$ cd project_name

# to install the dependencies
$ bundle install

# To start the server
$ rails s

Now in the browser you can access the rails starter web page using,

Wednesday, July 11, 2018

Getting started with Python Flask application with MVC structure

I have added a MVC structure and getting started with Python flask application in my Github. 
I will continue to contribute to this repository with Database connections and JWT Authentication.

Lets get started with Python and Flask :)

Here is the Github link for my project.

Structure your Flask application like a Rails Application.

I'm a Rails developer. I like the way a Rails application is structured and I wanted to implement the similar kind of structure for a Python Flask web Application. Flask by default will not give you this structure. So make use of the getting started with Python flask repository above. The Code structure will look like this:
|-- app
| |-- config.py
| |-- controllers
| | |-- hello_controller.py
| | |-- __init__.py
| |-- helpers
| | |-- common_helpers.py
| | |-- __init__.py
| |-- __init__.py
| |-- models
| | |-- __init__.py
| `-- templates
| |-- hello.html
| `-- __init__.py
|-- log
| `-- test.log
|-- README.md
|-- requirements.txt
`-- server.py


Make sure you have installed python :) To check python version,
python -V

Make sure you have installed python-pip. If you are using Ubuntu, you can apt-get like this
sudo apt-get install python-pip

To use the Python Flask Starter template.

Step 1 : Checkout code

git clone https://github.com/srikanthjeeva/python-flask-getting-started.git cd python-flask-getting-started

Step 2: Install dependencies

(use sudo if required)
pip install -r requirements.txt

Step 3 : Start the server

python server.py
In browser go to,
or for UI