Andrew SadauskasFollow on twitter Follow on Google+
How to start developing a web app using Ruby on Rails
Recently, StartupSmart looked at developing web apps in PHP. However, many developers choose to use an alternative framework called Ruby on Rails.
So what does Ruby on Rails development entail and how do you get started?
StartupSmart spoke to freelance web developer and Melbourne Ruby group co-organiser Pat Allan to find out.
Allen explains that at its simplest, Ruby on Rails is made up of a programming language called Ruby and a web app development framework called Rails.
“Ruby is a dynamically typed programming language developed with programmer happiness in mind, and has been around for about 20 years now,” Allan says.
“Rails (or Ruby on Rails) is a framework for constructing web applications. It’s written in Ruby, and you write your own Ruby code to extend the framework to build your own apps (it’s not an app in its own right).”
A key feature of applications written in Rails, Allen explains, is that they are divided up into three parts, known as ‘models’, ‘views’ and ‘controllers’.
“From Rails’ perspective, the models are your data objects – e.g. user information, blog posts, purchase details – whatever data your app needs to use or create. This data is usually persisted in a relational database like PostgreSQL or MySQL,” Allan says.
“The views are the presentation layer of your web application – the HTML that the browser displays, and any manipulation of that HTML to display dynamic content, including data from your models.
“The controllers are the glue that connects views and models together – they load up specific data objects, and choose which views should be sent back to the browser.
The ability to extend the Rails framework comes by adding libraries of already written code, which are known as ‘Gems’.
“Gems are collections of Ruby code (libraries) with a focus on specific functionality. There are gems for dealing with Twitter, downloading files, mathematical computations, testing, complex data searching, and much, much more,” Allan says.
“The value of this is it saves you from having to re-invent the wheel. Quite often you can end up building on top of others’ hard work instead. Of course, if you can’t find a gem for what you need, you can write one yourself – everyone is allowed to publish gems.
“Rails itself is a handful of gems, broken out into (mostly) distinct features such as dealing with HTTP requests, interacting with databases, and connecting models, controllers and views.
For Allan, one of the key strengths of Ruby and Rails is its developer community, which includes events aimed at everyone from beginners to web veterans.
“There are a great deal of social events in the Ruby community, especially in Australia, with Rails Camps twice a year, a big conference once a year, occasional RailsGirls sessions, and numerous meet ups in most major cities. These events help us to connect with each other, share our knowledge, learn new things, find new opportunities for work, and make a few new friends,” Allan says.
“There are many online tutorials out there and a growing number of online courses as well. Peepcode’s videos (now part of PluralSight’s extensive library of content) are top notch and worth every dollar. Ryan Bates’ enduring legacy of RailsCasts is an amazing (and free!) resource, alongside his more detailed paid offering. Michael Hartl’s tutorials are another source of detailed information.
“Having mentors available in person can also be super helpful, though, which is why events like RailsGirls and InstallFests are so valuable.
Allan goes on to explain that the Melbourne Ruby group has its own Meetup group. From there, developers can find out information about its regular presentation evenings, hackfests and InstallFests, which are aimed at new developers.
Finally, Allan’s advice to anyone thinking about coding a web app in Ruby on Rails is to just get started.
“The more code you write, the deeper your understanding becomes, and then you can get a better understanding of other peoples’ code, which in turn helps you to learn new ways of doing things. This is becoming more and more easy given so much of the code we use (including Ruby gems) is open-sourced and available for everyone to peruse,” Allen says.
“The best way to become comfortable with Ruby (and programming generally) is to write a lot of code. Of course it’s likely not going to be great code at the beginning, but that’s fine.
“Finally: Don’t be afraid of what you don’t know. All good developers are in a constant state of learning – technology is changing all the time – so there are always opportunities to ask questions and find out how another piece of the evolving puzzle works.”