Ruby on Balustrade is a web appliance framework.
Rails is the framework, Ruby is the language.
Designed by David Heinemeier Hansson in 2005, it’s become acclaimed in the Internet startup apple for its acceptance by some of the arch “startups” of our time, including Stripe, Uber and Groupon.
If you ambition to apprentice to affairs in Ruby on Rails, this tutorial should accord you an overview of what to do. I will not go into specifics because I just ambition to accord you an abstraction as to the anatomy of an application. If you chase what I propose, you should added absolutely acquire how these applications work.
All software applications plan in the aforementioned way -
- Abstracts is inputted
- Abstracts is processed
- Abstracts is outputted
The way the abstracts is inputted and candy is abased on the belvedere your appliance runs on. How it is outputted depends on your application.
The aberration with web applications is that their argumentation runs on a server, with the abstracts IO accepting anesthetized through the Internet (specifically, the HTTP protocol).
The aggravation of web apps is that you crave the adeptness to acquire entering data, and acknowledgment responses. This is handled by a web server affairs (NGinx or Apache). I’ll explain this in a minute.
When you actualize a section of software, you accept to accede the “stack” on which it runs.
The “stack” is all the software appropriate to run your application. In the apple of desktop games, for example, the “stack” may cover the brand of DirectX or a accurate cartoon driver.
The capital hold-back for ambitious web appliance developers is compassionate how the “web” software assemblage works. Web works analogously to built-in applications, except for one audible aberration – stateless.
The “Internet” operates beneath the HTTP protocol. By nature, this is accepted as a “stateless” agreement – anniversary appeal you advanced is advised absolute to the last. Unlike stateful protocols (which absorb state), stateless protocols accept to clean the application’s accompaniment anniversary time.
Whilst this agency annihilation to a lot of people, the point is that if you’re traveling to advance a web based application, you allegation to use a framework or technology set which makes the stateless attributes of HTTP as chip as possible. A lot of pertinently, you allegation an affidavit arrangement which rebuilds the user’s affair on every appeal (I’ll explain this in a second).
Ruby vs PHP
Ruby (the language) is affiliated to PHP – they are both procedural and both are acclimated heavily on the Internet.
The capital aberration amid Ruby and PHP is that PHP is accessed anon on the client-side, Ruby needs a proxy.
Applications such as WordPress are congenital with PHP because it’s free, accessible antecedent and can be run on any LAMP (Linux Apache MySQL PHP) server (which is basically all of the aggregate hosting in existence).
The point with Ruby is that it is a LOT added bitchy than PHP – it requires active processes to advice it accomplish and can about abort to alpha if any issues arise.
To get started, you allegation three things:
- An IDE (Integrated Development Environment)
- A Ruby-Compatible Web Server (Heroku)
- Ruby, Balustrade & GIT Installed On Your System
I’ll explain how it works.
An “IDE” is a argument editor with the adeptness to anticipate the cipher you input. I currently use Atom (free) from Github. You can download it from Atom.io.
The IDE allows you to address the code. Whilst you’re chargeless to use a accepted argument editor (Notepad or Notepad++), it’s abundant bigger to use a arrangement such as Atom or even Visual Studio, as to accretion the abounding functionality of the accent (linting etc).
From here, you’ll aswell allegation to install Ruby, Balustrade and GIT on your development system. Ruby is the programming accent (nothing works unless you accept it), Balustrade is the framework which allows us to body the web based application, and GIT is the SCM (Source Cipher Management) arrangement we will use to advance our cipher to our server.
For server technology, the easiest is to use Heroku (Heroku.com) – a absolutely managed system. You can get started for free, with upgraded capacity, acceleration etc added at added annual cost. If you’re adequate ambience up your own server, you may ambition to use the brand of DigitalOcean.
It accept to be acclaimed that aggregate hosting does not plan for Ruby based applications. You not alone allegation GIT admission (typically through SSH) but the server is aswell appropriate to run Ruby as a active process. This cannot be done with aggregate hosting (unfortunately).
Installing Ruby & Rails
The aboriginal footfall to programming a RoR appliance is to install Ruby & Balustrade on your system.
Whilst there are altered agency to do this, depending on which belvedere you’re active (Windows/Linux etc), there is a amount set of accomplish to follow:
- Install Ruby
This is done either from source, or by appliance a pre-compiled version. If you’re appliance Windows, you will allegation to install anniversary basal separately.
- Install RubyGems
This is the abject set of protocols which allows you to download all the added libraries for Ruby – the “gems”. These gems are acclimated to accommodate swathes of functionality for Ruby web development. Part of what fabricated Ruby acutely adorable in the aboriginal abode was this all-encompassing set of adaptable functionality. Balustrade is a gem, for example.
- Install Body Tools
In Unix systems, you’ll ambition to install the “build essential” library, Windows will crave installing the MSYS2 toolset. Both of these accommodate the arrangement with the all-important accoutrement to abridge the countless of self-building gems (such as MYSQL2 and RMagick).
- Install Rails
After this, you can run “gem install rails” to get balustrade installed. This will abode all Rails’ binaries assimilate your system, giving you the adeptness to advance with the framework.
- Install an IDE
An IDE (Integrated Development Environment) is the software acclimated to ascribe cipher into the system. Whilst they are just adored argument editors, they do accord you such functionality as linting, cipher highlighting etc. We use Atom but you can aswell use Sublime Argument or a bind of thers. If you feel confident, you may just ambition to use Notepad.
- Install GIT
GIT is an SCM (source cipher management) system. It gives you the adeptness to actualize a “repository” and advance it to an alien web server. This technology / address is basically like FTP on steroids, and is the primary way that Ruby cipher is “pushed” to servers. You accept to download GIT alone on your arrangement (from git-scm.com)
- Start Coding
With the aloft installed, you just allegation to alpha coding. To do this, you allegation to browse to a new folder, amount up CMD and blazon “rails new [[app name]]”. After acute “Enter”, the accepted appliance files will be placed assimilate the harder drive, acceptance you to adapt them and analysis them on a bounded server. This is the alpha of your application.
Without accepting into specifics, the key affair to bethink with Balustrade applications is that they are “done for you”.
Rails has a assemblage alleged “convention over configuration”. This agency that the Balustrade framework has been advised to accord you as complete way as accessible to body and arrange a web based application.
The framework is accepted as an “MVC” archetypal framework (model, view, controller) – which agency that anniversary time you advanced a request to the application, it uses a aggregate of a “model”, “view” and “controller” to body a response.
As such, if you actualize the new Balustrade appliance on your system, you will bound see a ample amount of folders. The alone ones which amount (in the beginning) are those amid in the /app directory.
In here, you’ll see the brand of “assets”, “views”, “models” and “controllers” folders. If this agency nothing, don’t worry. I’ll explain the base of how it all works here.
MVC has been about for abounding years.
It works in the aforementioned way for every implementation:
- If an appliance receives a request, it routes the appeal to a controller
- The controller again pulls abstracts from the model (which talks to the database) and puts it into a view
- The view is alternate to the user
In the case of Rails, the “view” is an HTML book busy with the abstracts from the model. For example, you may accept the afterward basal bureaucracy for a simple “hello world” application:
class ApplicationController < ActionController::Base
@name = User.first
Hello <%= @name.first %>
class User < ActiveRecord::Base
# connects to the DB
# has action of id | aboriginal | endure | dob | created_at | updated_at
The aloft will acquiesce you to advanced a appeal to “http://127.0.0.1/” and should accept the aboriginal name of the aboriginal database user.
Pushing To A Web Server
The final footfall to accepting set up is to advance to a reside server.
Whilst you can use a VPS of your own (it has to be a VPS because aggregate hosting does not accept SSH access, nor supports Ruby applications), the simplest and a lot of able way to get started is to just use Heroku.
We still use Heroku for staging server purposes (when you broadcast a web application, it’s acclaim you use a “staging” server to analysis the application, and a “production” server to host the appliance publicly). I’ve fabricated abounding mistakes afore by acid out the development server.
To advance to a Heroku server (free), I’ll briefly explain the process:
- Accessible a Heroku annual (I anticipate you may allegation to accommodate agenda data – don’t worry, they don’t allegation for their chargeless tier. It’s to validate your character so you don’t accomplish actionable sites)
- Actualize an “app” in their dashboard
- Click assimilate the app – you’ll be accustomed a “git” URL
- Copy this URL and arch aback to your Balustrade application
- In CMD, blazon “git add limited heroku [[heroku link]]” (replace [[heroku link]] with the git URL Heroku gave you)
- Columnist enter
- Now, amalgamation up your appliance (git add.) (git accomplish -am “First Push”)
- After inputting these lines, blazon “git advance heroku master” and columnist Enter
- You’ll accept to admission your accreditation – do this and the repo should be beatific to Heroku
- After this, Heroku will body the appliance and “deploy” it on its own namespace ([[app-name] herokuapp com)
- Browsing to this namespace will appearance you the app
After accomplishing this, it’s up to you to again administer your arrange agreement in your own way etc. I would acerb apostle appliance Heroku for staging ambiance servers; you’ll acceptable ambition to use such casework as DigitalOcean for production.
Of course, web appliance development is affective advanced constantly.
Due to the acutely low barriers to admission (free) and the across of assets available, abounding humans are fatigued to Ruby on Balustrade development.
However, don’t let it fool you. The ambit for earning appropriate money from this profession is absolutely abased on two factors – your skillset/ability, and your admission to a market.
Unfortunately for abounding ambitious developers, their ballsy dreams of creating the next Groupon / Stripe etc are burst if they admission the “real world” — area audience don’t affliction about the cipher you use and just ambition the cheapest band-aid that almost works.
The key for any Balustrade developer is to accumulate advance into their programming skillset, even with added languages. Ruby boodle abounding developers because of its simplicity. Affective college up the programming amount alternation (into the realms of C / C++ etc) accessible up a lot added abiding positions.
It is accordingly my advocacy that you always advance yourself to attending at new UI ideas, new agency of accomplishing things and about convalescent your skillset as required. Attend hackathons, accommodated added developers and about advance your acknowledgment to the accretion industry. This should present opportunities for you as you develop.
– web hosting free ftp access