Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
by
Lessons:14Length:2.4 hours

Next lesson playing in 5 seconds

Cancel

Free Preview: Get Started With Ruby on Rails

Introduction

02:39
  • Overview
  • Transcript

Ruby on Rails is an open-source framework that allows you to quickly and easily build applications for the web. It's a framework designed with developer productivity and happiness in mind. With Rails you can create web applications with very little effort through strong conventions, sensible defaults and a great set of libraries. If you want to get started building web applications, Ruby on Rails is a great place to start!

In this course, you'll learn about developing web applications with Ruby on Rails. We will build a simple task and project management tool together. In so doing, we'll cover the foundations of Rails: models, controllers and views. We'll also go further, touching on most of the key features of the Rails framework: validations, migrations, the asset pipeline, email delivery, internationalization, AJAX integration and more!

1. Introduction

1.1 Introduction

Ruby on Rails is one of the greatest phenomenon in the software development industry. It is an open source web framework that allows you to quickly build applications for the web. If you want to get up to speed in developing your own web application, you should definitely study this tool. Hi, my name is Shozamata. I'm your instructor for this course. You'll learn about developing web applications using Ruby on Rails. The latest version, up to date as you can see, is 4.2.1. It was released a couple of months ago, but it proves to be a stable in today's software industry. In this course you will learn many different things. We will build an application that will support each different concept or at least most of them available in the Rails' framework. Rails is more than just a tool. It is an environment, a community, an effort by thousands of people around the world. As I've mentioned, we're going to learn Ruby on Rails by example. We're going to actually build a project of our own. It's going to be a project manager, as it has a simple yet solid business model. Which we can rely on and translate to a Ruby application. We will cover many different aspects. We're going to begin with a small boot strap of the applications, and then we're going to build our way forward. We'll learn about models, controllers, templates or views, as they're called. And these will be the very foundation of working with Rails. But after that, we'll take a look at some other aspects, such as the validations, how to write forms that mirror our objects in the application, how to use CSS and JavaScript through the asset pipeline. How do we run migrations that change the schema of the database? How do we send email? And how do we use internationalization to support multiple languages? You will learn all of this in this course. So I hope you're excited. I assume you have a basic knowledge on the Ruby language. If you don't, be sure to check out the Learn to Code With Ruby course. All of the basics and fundamental techniques on how to work with Ruby are there. Go ahead and check it out before jumping into this one. If you're already comfortable with Ruby, then jump right ahead. Let's go to the next lesson. We will learn how to bootstrap a Rails application.

1.2 Bootstrapping a New Rails Project

Let's begin by bootstrapping a new Rails application. Most of the operations will be performed in a terminal environment. So go ahead and choose a terminal application from your system. If you're using Mac OS X, you can choose the terminal. If you're on Linux, then you can choose the select a terminal application that's built in to your distribution. If I press the Windows key, I can see the terminal icon right over there. But if you choose the whole list of applications. Just go ahead for example to the search box and type in terminal. I have three different choices, but go ahead and choose the standard one. So I have my terminal of choice and I'm going to navigate to a folder of my choice. I'm going to switch to a particular directory using cd, and then for example projects/ruby. Now from here, I'm going to install the Rails gem. Type in gem install rails as it is and you'll be good to go. This will install the very latest version up to date. So press Enter and you should be seeing some sort of an output. It will demonstrate that effectively the gem is being installed along with all of its dependencies. Okay. You see that the latest version that's available is 4.2.1. Most likely, by the time you see this maybe a 5.0 version will be available. The major differences between those two versions will not be breaking changes, so you should feel comfortable with using this version as well. Let me clear the terminal really quick and type in the Rails new command. Rails is an executable application in the terminal. If I type in rails new, I will be able to bootstrap a new application. For this specific course, we're going to develop a project manager. So, what if I type in something like projects for the name with a K. You can figure out any name that you want. However, I advise you to choose a one word name. This projects name will be used as the name of the Rails application in the Ruby code. So stick to one word and you should be fine. So now that we have this, I can press Enter, and a bunch of different files and folders will be installed. After this, you can see the run instruction, which will bundle all of the dependencies into our application. Basically we keep a track of all of the libraries and gems that we'll need to use in order to run the app in a server. We'll need to wait a little bit until all of them are installed and only after that, we'll be able to move forward. Okay, there you go. You can see that I already have some gems installed in my system, but some of them were updated or installed fresh. There are loads of them you can see right there, there's a huge list. So most of the work is already done for us. Many of the features that make Rails so prominent in the industry, have to do with the fact that it comes with a lot of libraries already inserted. So now that the project is bootstrapped I can type cd and then the name of the folder. And from there I can type in the Rails command again. But this time, instead of typing new, I'll type in server. This will spawn a new web server that will take our application and run it. The information you see here is very straightforward. It is booting a new Rails app with this address. So, if you pick on this, I'm just going to select it and copy it. Then I'm gonna go to a new web browser. There you go. And then typing in the exact same location, localhost:3000. And look, our application is already working. The good thing about Ruby on Rails, is that you really don't need to do anything in order to have a working application. Even though this is just a dummy welcome page, it just works. So just based on the fact that we have this, we are able to run the application. No code was necessary, no bootstrapping of settings, nothing of the sort. So I'm just gonna close the server, because we really don't have anything. Instead, I'm gonna open a text editor. I'm gonna use VIM, because that's my standard text editor of choice. I'm gonna open the file manager, and explain to you some of the biggest features in a Rails application folder structure. There are lots of different files and folders, but only some of them are important. First of all I'm going to focus on the gem file. The gem file as you see here, has a bunch of different dependencies, namely the Rails gem and some others. These are standard in a Rails app. As they provide all of the features. The SQLite gem is a gem that allows us to integrate, or rather communicate with a SQLite database. You have similar gems that do a similar job, but for different systems. Such as a MySQL or a Postgres database. SAS, Uglifier, and Coffee are three separate gems that have to do with the way we compile the assets for our application. Namely, CSS and JavaScript. The default way of handling these files is with these gems. You write SAS and CoffeeScript files that get generated and also bundled into a single file. We're gonna need to resort to these in order to accomplish it. Next, we have the jQuery rails, which is standard in any Rails app. We're going to require jQuery into our application. Then, the Turbolinks gem, which is relatively new. It has only been present in Rails 3.2. Turbolinks allows us to have a similar behavior to Angular or Ember apps. Basically you generate the HTML to be loaded via AJAX. And you only load that HTML in between requests, without requesting the whole page and so on. Next, the Jbuilder and SDoc gems have to do with building JSON APIs and also fuller documentation on the actual rails framework. We won't be needing to use these, at least as of now. We have loads of different commented gems as well. The have to do with special features that you might want to have. But we're really not going to focus too much on that, since you are only beginning. Taking our first steps. In lines 35 and forward you have some gems that will allow us to ease in the process of developing the application and testing. Namely the Byebug gem allows us to enable a web console which is also here. Basically it allows us to run some code, and it will be returned into the browser window. Spring is also a gem that allows us to run the application and keep running it in the background. This allows for much faster development. So that's it on the gem file. This is one of the very important files. Because it basically allows us to add more features that rely on other gems. The other very important folder is the app folder. Basically, all of our code will stay in here. The controllers folder will contain our controllers, the entry point between the requests, and our code-base. The models folder will contain our business entities. Since we are going to create a project manager, we're going to have a project model. A task model, a comment model, stuff like that. These will be entities that will create value in our system. The views folder contains all of the templates, the HTML templates. We're going to resort to the ERB templating system. Basically it allows us to inject Ruby code into our HTML content. The other folders, we're not going to focus too much on them. Basically, the helpers have some methods that we can use in our views, the mailers allow us to send email, and the assets contain JavaScripts, style sheets, and images. So if you're thinking of doing design work yourself, you should have the images, JavaScripts and CSS files in this folder. Now another important folder, rather just a set of files are the routes file, and the database YAML file. Let's go with the database first. This is a YAML file. It works relatively like the XML declaration, but it doesn't use all of the tags. We have a default structure that has an ID, and basically it will tell us that we are going to use the SQLite3 adapter with a time out and a pool settings. These are just part of the SQLite3 specifications. And then for each specific environment were going to use all of those settings and then specify the database, which is very important. This is the path relative to our project boot folder, and basically were going to have a DB folder with the respective SQLlite file. Our database will be a file. The same goes for test. And also production. Our main focus in this course will be on the development database, because we're only gonna resort to the development environment. Next, the routes file. The routes file allows us to create routes, basically URL addresses, that will map to a controller. We have loads of different examples, but we're going to take a look at them later in the course. But mainly, it allows us to map addresses in our application, to map to a controller and an action. Next, and most importantly, we have the DB folder which will have, most likely, a migrate folder. This migrate folder, which you don't see here still, holds all of the changes that we need to make in the database. For example, when creating a new project model, we're gonna have a projects table. The migrate folder will contain a file that will allow us to tell the database to create that project's table. Usually you will do that by hand. You will go to the database, type in some SQL and the table will be created. This is not the case with Ruby On Rails. When generating a model so a project model class, it comes bundled in with a migration file which you just run. We'll have the chance to do that in the next lesson. In fact, we're gonna leave it at this in this lesson. This is just a basic explanation of the main components of our development in Rails. In the next lesson, we'll focus our attention on building a new resource.