>> GABRIEL GUIMARAES: This is CS50.
Welcome to Amazing Web Apps with Ruby on Rails.
So for anyone who's interested in web development and making websites, web
applications, Ruby on Rails is this amazing tool that Twitter, GitHub,
Groupon, and all sorts of really nice, and big, web applications are using in
the last few years.
And it's a really, really cool feature, a cool tool,
because it's new.
So it has all of the new powerful technologies incorporated into one
framework that helps you deal with all sorts of amazing things.
>> But what is a framework?
So a framework is basically something that creates--
when you start a website, if you started from scratch, like you open
gedit there, and you want to code all of your HTML, and code all of your
PHP, all of your CSS, everything from scratch--
that's just going to be a lot of work.
And a framework literally gives you half of the website done already.
So you start off with half a website that has everything there for you.
Like the database connections, and all sorts of things that you have to worry
about if you're doing it from scratch, you don't have to worry about those
low level details.
>> But today we're going to export one of the websites that the freshman of the
class of 2017 are probably familiar.
So this website is the website that I did for our class over the summer.
It was a website where the students of the class of 2017 could log in and
interact with each other.
And then this is a map--
everyone, where people are.
And we had a book game, a songs game where we saw people's songs and
people's books.
What they like to read, what they like to listen to.
And the most interesting part of it is that it literally took me three hours
to code all of it.
Because if I had to do everything from scratch, like opening up gedit, it
would probably have taken me 20, 30 hours.
But with Ruby on Rails, because everything was already set up for me,
it only took me three or four hours, or something like that.
>> So what is Ruby on Rails.
Ruby on Rails, again as we already said, is a framework.
This is a picture of a framework.
So you're going to start building a house, you already have half of the
house done.
That's the framework.
And Ruby on Rails is exactly like that.
And you should think of it as, you start a website, you start your web
application, we already have half of it done there.
But first of all, what is Ruby?
Ruby on Rails uses the model view controller, which is paradigm, which
is a really interesting--
and all of the applications nowadays use something like that.
This idea of separating things into three parts, the model, the view, and
the controller.
We're going to talk a little more about that later.
>> First, what is Ruby?
So this is Ruby.
And this is the symbol of the language called Ruby.
Ruby is one of the newish interpreted languages, so script.
It's a language that's not compiled like C. It's compiled on the run.
So that's good because, just like PHP, for example is also interpreted, is
not compiled.
That's good because its portable.
So you just pass your code from one machine to another.
From a Linux machine, to a Windows machine, to a Mac or Apple machine, or
something like that.
And you don't need to worry about details regarding each of the specific
operating systems.
It's going to work everywhere.
>> And Ruby is a language that--
you guys probably remember this.
People use the hash function implemented in C for the hash table
last week and had all sorts of segmentation faults.
And then things worrying about whether that string i there, the string i
here, was actually lowercase or uppercase, or these kind of worrisome
low level details.
Well in Ruby, if you want to implement a hash table, this is exactly how you
create a hash table.
You say, dictionary, that's the name of my variable, = "Hash.new".
And then dictionary["foo"], and when I'm adding foo to my hash table, I'm
just saying foo is there.
>> And then if I wanted to check if foo was there, I just say if
dictionary["foo"]==true return true.
Whoa, and that's your hash table.
That's the implementation of hash table in Ruby.
So everyone wished they could have used something like Ruby for last
week's pset, right?
We have all sorts of reasons to want to use a language like Ruby.
Ruby has gems.
Gem is a name for a kind of library in Ruby.
>> So all sorts of interesting features that you can have, for example, if I
want to integrate my application.
That Harvard 2017 application was integrated to Facebook.
So you could log in, via Facebook, to the app.
So if you're going to do that, you don't need to worry about sending some
HTTP request to Facebook, and waiting for the response, and forcing the
response, and blah, blah, blah.
You just download the gem that does all that for you.
And then you don't need to worry about all of that.
>> And then plenty of help online, of course.
There are many, many, many websites that are going to help you both with
Ruby and with Rails.
And it is lots of fun to code.
Exactly because you can stop worrying about those not so fun problems.
Like if something is lowercase or upper case, and then why is this
giving you a segmentation fault, and you can really dive into the very
interesting stuff.
To dive into the really cool problems.
>> So Ruby is just like to C in a sense.
So it's not going to be that big of a jump actually.
So puts, that's our print app in Ruby.
I think you could use print too, but puts is what everyone uses.
So just puts "Hello World".
You could, or you could not, have the parenthesis encircling
"Hello World" there.
You can just choose whether or not to use that.
And then x="1".
A while loop looks pretty much the same.
It just has less syntax.
It's kind of cleaner a little bit.
And then if x>25 puts"Big!" and else puts"Small...".
And it's kind of C in that sense.
>> So if you look at that, you can approach probably understand
everything that is going on.
But it's more powerful.
More powerful because, more than that, it can do things are not that--
some kind of hackage a little bit.
In C you couldn't do in just do with one line.
For example, puts"I am#{x}".
This is just syntax for put the value of x here, and don't print the
character x.
In C you had to do the percent d, and then put up the variable x after the
comma here, or something like that.
>> And in Ruby there's a shorthand for just doing that.
And puts this, if x>3, so you can put the if all on one line.
And then a list.
Lists in C, like an array, you have to keep track of how big your array is or
otherwise you get a segmentation fault.
Your array is only one type.
So it's either an array of charge or an array of integers.
In this case, I created a list here, that's an array, that has the first
element is a string, John, and then four, two-- those are integers.
And then I just add, list, the Left Angle Bracket, Left
Angle Bracket, three.
That means just append something to my list.
>> So it's kind of more interesting because if you wanted to use this as
just a simple list of integers, you could, totally.
That's totally fine.
Just put integers there.
But if you wanted to do something that's more compelling, that has other
things, that has--
I don't know, all sorts of lists in there, or other objects that are more
interesting, you can totally do that.
It's totally fine.
And then if you want to iterate through the list, you could use the
more C-ish kind of approach.
That's for loop, you to initiate a variable, i="1", or i="0".
And then you go, and iterate, and get all of the elements.
>> But you could also use this more Ruby-like approach.
That's just like a list.each.
That's just saying, return me all elements of the list.
And do with each element, call them elem.
So this is just a name that I'm giving to each element.
And now this is going to repeat for all the elements, and elem, it's going
to be the way that we access that single element.
So you could totally stick to the C approach, but this works too.
And it is exactly the same thing, OK.
>> And other than that, it is really, really easy to integrate Ruby and HTML
since you guys are interested in web applications.
HTML is definitely something that you're going to use a lot.
And here if you wanted to put Ruby in HTML, just start here, <%.
That means, here Ruby starts.
And then %>, kind of like PHP in that sense.
Here Ruby ends and then you can just put your if in here.
And then I have some variable user.logged_in.
In Ruby, we usually add those, either interrogation mark or exclamation
mark, like a bank character, just to kind of
distinguish between our functions.
But you just put that for your own sake.
It's not something that changes anything in the functionality.
>> So just to remind me that this is a function-- and functions in Ruby,
rather than C, as I said already, they don't need the parentheses.
So that logged in thing, that's a function, that's a method.
But you don't explicitly need to put the parentheses in there.
So just asking if the user's logged in, and if the user's logged in, now
HTML starts again.
So Welcome, and here I print the user.name.
And that's it.
So that's pretty straight forward, how you integrate Ruby with your HTML.
And resources, as I said, there are all sorts of resources for Ruby.
You guys can all look this up afterwards because both the video, and
the slides, are going to be available online.
>> And now let's get into Rails.
Rails is love.
Rails--
so Ruby is his language.
OK, just like PHP, just like Python.
It's a high level language, not like C. C's a middle, low-level language in
the sense that Ruby you don't have to worry about memory reallocation, and
pointers, and those kinds of things.
But Rails is this program that was written in Ruby.
And it uses Ruby, in order to have this framework, for you to be able to
build awesome web applications.
>> So you have to first install Ruby on your machine, but most machines
already have that.
And then install rails on top of it.
We're going to talk about that later.
And why Rails?
So MVC, that's the model view controller we talked about a little
bit, makes everything simpler because it divides things that are
conceptually different into different parts of your application.
Less time spent on low level problems, again, and very, very
popular right now.
So for all those who are interested in the start up scene, or in something
like starting businesses, and people in the technology market who are
starting their own business right now are really, really fans of Ruby on
Rails because it's so fast.
>> So you can get something up and running in less than a day, and that's
really a very compelling argument to use Ruby.
And Rails 4.0--
it's very fresh from the oven now.
So Rails 4.0--
I think the first release was in March this year.
And it's really nice, it has all sorts of new, cool features.
So Ruby on Rails is a framework that's constantly being updated to have all
of the new technology.
>> The first time I tried to use Ruby on Rails, I had this trouble because I
created my first web application, and it looked exactly like that.
So it creates all of those files for you, and I had no idea what--
what is this?
It created all those files, and I only wanted to create a simple program, a
simple HTML website.
And I couldn't even do anything.
So I was a little bit overwhelmed.
But that's one of things that once you understand it, everything becomes so
much clearer.
So don't be overwhelmed by the first sight of what you create at first.
>> So what happens is Rails creates all those files.
So one of that is doc, documentation.
Db, that's related to the database.
Lib, that's libraries log.
Public, script, and some things.
Pretty much all you're going to worry about is the app folder, up there.
That's the folder that contains your application.
All of the other files--
some of them are important, and you're going to learn about that later.
But they're just here to contain the framework.
So the first cornerstones of the house you guys are building, OK?
>> But the app folder--
that's the really important one.
And the app folder has assets.
Assets is pretty much everything that's coming.
Images for example, everything that's static that's going to be downloaded
to your website.
So images, JavaScript, CSS--
those kinds of things are assets.
Controllers--
we're going to talk more about what are controllers, models,
and fields in a second.
And helpers are functions that you can use all over your code
to help you do something.
Functions like logged in, for example-- user.loggedin.
That's a function that probably you have to use in all parts of your
application.
So you can put something like that in your helper.
>> Mailers--
that's if you're going to send an email to your users, you
want to use a mailer.
And models and views, we're going to talk about that right now.
So the model view controller, that's the basic cornerstone of Ruby on
Rails, and most frameworks nowadays, to be honest.
So again, we separate all of our code into three different parts.
The model--
the model is basically the database.
It handles things in the database.
>> So each table in the database has a corresponding file within the model.
So it's kind of a table for your users.
So you're storing information like the user name, their emails, their
address, their password, and things like that.
You're going to have one file in the model called user rb--
rb for Ruby.
And there you're going to have all of the methods and the variables.
The variables are going to correspond to the user name, the email, and
everything.
>> And you're going to have the methods.
That will be something concerning--
you're going to handle this information in the database.
To create a model with Rails, you just use Rails generate.
And to create things in Rails, you actually need the terminal.
So it's a very terminal based framework.
You just log into the terminal, and do Rails, generate model.
And the name of the model is user.
And I just want to have two variables, two columns, in my table.
So that's email.
Email is a type string.
Password, password is also a type string.
Those are the only two things.
It's kind of a simplistic user table.
But you could totally put a hundred thing's there if you wanted to.
>> And Rails also makes it very, very simple to have all
sorts of database relations.
So usually, when you have tables in your database, they're not very much
independent of one another.
Let's think about.
You want to buy and sell products online.
OK, so you have a website where you want to buy and sell products.
So each user has many products that this user is willing to sell.
And each user also has many transactions that are ongoing, or
something like that.
And the transactions are with another user.
Each transaction belongs to two different users.
The user that's buying and the user that's selling.
>> So those are the so-called database relations.
And here we have exactly those keywords, has many and belongs to.
Those are the most important ones.
And you're just going to say, for example, this is the example of a
model in the Harvard 2017 website.
Again, the students in here--
each student on the website, student is a model, is a database table.
Each student had many books because you could say, what are your favorite
books, right.
So each book belongs to a student down here.
And attribute accessible--
that's just saying, those are the variables.
Those are the variables accessible from this model.
And the variables are the author of the book, description, genre, and
title of the book.
So just the information concerning the book.
>> And here I have a method that simply sorts everything.
So define and end here, that's just saying, here comes my method.
Self.sorted_all.
That's just, give me everything sorted, and that's how you implement
the sorting algorithm, which is fairly easy.
But basically, this is how a model looks like, OK.
Does anyone have questions regarding this database thing?
Relations?
Is that clear?
Yes.
>> AUDIENCE: Can you do the sort algorithm?
>> GABRIEL GUIMARAES: The sort algorithm, OK.
When you get used to Ruby syntax, it's going to be clear.
But basically, elems is Book.all.
So book is the name of my model.
When you create a model, it comes with all sorts of nice methods for you.
So dot.all is a method that returns all books.
But find, for example, would search for one book and return that book, or
something like that.
And so elems is everything.
And I'm just saying elems.sort.
Sort is a built-in Ruby function.
>> And, do ab.
So this do again is--
you're going to sort.
But you're going to get this argument for me.
And the argument uses-- this is one of the harder things in Ruby actually,
this do thing.
But once you understand it everything comes very, very intuitive.
So the ab, this is saying the place holders that I'm going to use-- like
the variables I'm going to use, are going to be called a and b.
And those are the books.
>> So because sort needs to compare elements, remember that?
So when you sort things, you compare two elements.
I'm going to say that every time you're going to compare--
so this is, I'm passing to sort an argument.
And the argument is everything from do to and here, OK?
And this argument, is just telling sort how to compare.
Sort would work here, but it would compare with their
default comparing algorithm.
I want it to compare in a very specific way, namely, when the book
was created, when each book was created.
>> So I'm saying, say the name of the first book is a and the name of the
second book as b, I want sort to sort something based on b.created_at this
weird symbol, a.created_at.
And that weird symbol is shorthand for if one is bigger than the
other, return 1.
If one is equal to the other, return zero.
If one is smaller than the other, return minus 1.
So that's what that weird symbol is.
>> But that's not important.
I mean, what I want you guys to get now is the idea that database--
you can have the model there.
So you don't have to worry about connecting and using SQL statement,
and things like that.
It can also create doors to SQL injection and all
sorts of security problems.
In this case, you don't worry about that.
You just use methods like book.all.
And that, in the background of course, is going to your database, and it's
going to use a SQL statement to get all the books.
But you don't have to worry about that.
That's the takeaway, OK?
>> And when you have a belongs_to statement like this, that means that
once you have a book object, you can see what is its student.
So which student has this book?
So we can just use book.student, and that gives you what the student is.
And that's a really feature to have.
>> OK, now the view.
So the model is what interacts with the database, right?
The view is basically HTML, and CSS, and some JavaScript.
And that's what the user actually sees.
The user's not going to see your database.
He's going to see some data from the database embedded in the viewer.
Ruby on Rails makes it really simple to make fields.
First, because it already creates it for you, out of the box, a layout.
>> A layout is basically something that--
if all of your pages have a logo on top and, I don't know, some menu or
something like that, that all your pages share in common, then you don't
need to create many, many, many HTML files where all the files have that
same HTML code.
I mean that's dumb because you're just repeating code among different files.
That's definitely not a good approach.
>> So Ruby on Rails creates this layout for you.
And this is just saying, all my pages are going to have this HTML, this head
title here, and those are style sheet link tag.
Plug in here all my CSS.
Plug in here all my JavaScript and some meta tags.
That's just something that they do automatically for you.
And then, end the head, now here starts the body.
And now this is my actual content.
So if I wanted to put something like, a menu here, I would put it right over
this place, or something like that, so that all of my pages shared it.
So the layout is shared by all the pages.
>> Now that yield here just says , no matter what pages this is in, just
plug in the content of that page in here, OK?
And now this is, for example, the content of one page that's going to be
plugged into this yield statement automatically by Rails.
But this is a layout shared by all pages.
And this is an example of one page.
And this is exactly the page that lists all the books.
So this is a basic HTML table up top.
So listing books, a title, author, description, genre.
>> And here we use, again, some Ruby syntax, @books.each--
@ kind of says that your variable is global in a sense.
Because this variable was actually declared in the controller which
you're going to see right now.
But just take for granted that this @books is a variable that is a list of
all of the books.
So books.each, do, and again, this is just saying how do you want to name
each of the iterators so that we don't have to worry about a four, int i
blah, blah, blah.
We just take each of the elements and use them.
>> So this is the book, and then just print here. book.title, book.author,
book.description, and blah, blah, blah.
And here's a link_to.
So link_to is just a link tag that a user can click on and
goes to another website.
Link_to, show that particular book.
So if the user is very interested in this book, then he can click on show.
Or click on edit, if he wants to edit the book.
Or destroy, if he wants to delete the book from the database.
OK, does that makes sense?
Good.
>> Finally, the controller.
So basically the controller is the interface between the
model and the view.
So the model is the part of your code that has database--
each table in the database has a respective file in the
model, and so on.
And how do the model and the view interact?
So, through the controller.
What a controller does is it is the model for something like, for example,
put all of the book inside of a variable.
Like this one, @books.
>> And it needs to be global with this at thing because it's going to be
accessed by the view.
It's not going to be used within the controller itself.
And it just slows information that the view is going to use.
For example, the controller checks if the user is online.
And how does it do that?
It actually asks the model because the model has the
information about the user.
It has a users table, the books table, other tables.
So the controller asks if the user is online.
If the user is online, the controller handles things like putting a cookie,
or something like that, to put the stamp to say that the user is online.
No need to log in again.
>> And it's going to load a variable called user, for example, that the
view can use.
And the view can put something here, for example, welcome user.name.
So it's going to say, welcome John, welcome James--
something like that, right?
So all of those variables used in the view are going to be loaded in the
controller and are going to be pulled up from the model.
>> This is the example of a controller.
So we have, basically, each--
we call those things actions.
So index is an action.
It's a Ruby function.
It's a Ruby method in there.
But for the controller calls those things actions.
And each action is related to a route.
So here this route, for example, is a get statement /books.
So if you go to harvard2017.com/books, what's going to happen is this code is
going to be called.
>> And there is a file--
let me open this real quick.
There's a file called raw file.
It's not opening.
So there's a file called raw file that basically matches--
oh, now it's opening.
Here, routes.
So basically matches a strain, activation /new for example, to
something in the controller.
So there's this controller called activation controller, but out here,
we have the books, for example.
So matches--
books/new, to the controller books, the action new.
So basically, very straightforward things.
>> And here, if you had to get /books, slash the ID of the books, slash new,
you're going to go to that Ruby method down there.
So here, what this index is doing is just loading book log.
That's something that--
I log all of the books in a log.
And sort it all.
So this going to return all the sorted books.
This is, again, in the database.
So this is a method of the model.
You saw this method being created in the model.
Now this is just loading all the books and putting that in a variable that
can be seen by the view.
>> Because you can't, in the middle of your HTML code, you cannot call
something directly from the model, because for two reasons.
First, for security reasons because it's not really interesting to be
loading information directly inside every HTML that's in the database.
And second, to keep your code really organized.
So separate exactly the different parts.
So BookLog.sorted_all, this in the database and this is going to put into
a variable @books.
And now this variable is accessible within your HTML code.
So you can just put all of the books there just like we did, right here.
This is the variable.
>> And visits respond_to do | format |, this is just a kind of Ruby syntax for
if the user is asking me for HTML code, I'm going to
respond with HTML code.
If the user asks me with JSON code, which is something that web apps use
to communicate between themselves, they usually use JSON or some other
kind of thing.
So it just responds using those two different formats.
But for a normal user, this wouldn't need to be here.
You would just respond with HTML, and that's fine.
So don't really worry that much about this.
This is the only line of code in our control as it's loading from HTML
database, putting in something that's accessible by the view.
>> And then new, so here I'm creating books.
But to create books, I need a student because I need to know the student
whose books this belong to, right.
So @student=Student.
Student, again, we're starting with a big S is the model student.
OK, so this is the model student, this is the model book log.
Student.find, so I'm going to find a student using the parameters ID.
params.id, this is just get me the value of this ID that was passed--
and the URL.
>> Just going to search for that student.
And first, we're going to check if the student has some songs
and blah, blah, blah.
And this already handles the case when the student
doesn't exist, for example.
And then, else, we just respond to the same thing using HTML.
And then we can let the user create their songs.
So this is new.
New is usually used for, let the user create something.
And then there's the create action that's usually used for--
actually put the songs in the database or something like that.
But once you start using Rails, those things are going to be
much, much more clear.
OK, cool.
Any questions so far?
Does it makes sense with controllers, models, fields--
yeah?
>> Again in your Rails application--
so all of that can be found in here.
So you have app, controllers, those are all of my controllers.
So for example, books control.
That's the one we just saw.
And then views.
And each controller has an associated view, right?
So automatically when you call this index here, for example, or when you
call this books new, then the view, books, new is going to be called.
>> So Rails does everything automatically for you.
So every controller has an associated view and all of the models--
here I have one, two, three, four, five models.
But this is a student model, so those are the variables that all the
students have-- localization, date of birth.
Students is a little bit more complicated because each student has
more different method associated to it.
But this is just handling the table that had all the
students in the database.
>> And, OK, installing Rails.
Installing Rails, to be honest, is not the simplest thing.
But once you get past everything, it's very, very easy.
So installing Rails, you just go to the website, rubyandrails.org/download
and follow their instructions there.
Download everything.
And you can do that either in Appliance, in the CS50 Appliance, on
Windows, on Mac, or any operating system of your choice.
Ruby on Rails runs on everything.
>> Odds are you already have Ruby installed if you have a Mac or--
in the appliances I think Ruby is--
I'm not sure.
And then you just have this installed.
And if you want to create a new web application, you just
do Rails, new, blog.
Rails, new--
I don't know--
the name of your website.
And it's that simple.
>> It's going to create all of those files I just showed you.
But the model, the view, and the controller are not going to be
populated yet.
You're just going to have to go there and populate those three folders.
So odds are, you want to create a model, for example, implement one
model first.
So again, always trying to bite smaller bits of a problem at a time.
>> And then let's say, create a model for your users.
That's the first thing if you have users.
Then I want to create a model just like we showed here.
Rails, generate, model, user, and then emails string-- we have that here.
And just create that model, yes.
Rails generate model User email:string password:string.
>> And then you create a controller that deals with the user.
And you can create new users and do those kinds of things.
And then you can move on to creating the rest of your website.
Cool, questions?
Yes.
>> AUDIENCE: [INAUDIBLE]
>> GABRIEL GUIMARAES: Yes, yes, you definitely have to go into the view.
That's a very good question.
So the view is what actually contains your HTML.
So it's what the users are going to see.
Again, here, this is an example of a view.
It has HTML code and Ruby code at the same time.
So the Ruby code is there to put things from the database, for example,
that were loaded at the controller.
So that variable @books, for example, has all of the books and the table
books at the database.
We made sure that it had in the controller.
>> And the view--
each of the pages off your website is going to have one associated view.
So if you go to the home page, the very first page, harvard2017.com.
That shows one page.
And then you go to slash profile.
That's going to go to a controller that's a profile controller.
And the profile controller is going to give you the profile view.
And the profile view is going to look somewhat like this, but it's going to
have information about the user, and not about the books.
>> So it's HTML code and CSS and those things that a user sees
with the Ruby code--
that actually prints things from the database.
Is that more clear?
I hope.
>> AUDIENCE: The HTML code is used to actually make the website that the
user sees, but the Ruby code is what makes the website work?
>> GABRIEL GUIMARAES: The Ruby code gets converted to HTML.
So what the user gets is only HTML, OK?
It's only HTML.
This book.title is going to convert to the value of book.title in HTML, OK.
So this is all in the server, and so this depends on what books are there
in the server right now.
But what the server would immediately sense is only HTML code, OK.
>> But the view just gives the layout of what the HTML was going to look like
and what the variables are going to be.
This kind of a print out, OK.
Those things there are basically print outs.
They're going to print variables, OK.
So what is only HTML, those--
author, title, description.
That's static content.
That's not going to change.
That's just plain HTML code.
Those are the print outs for variables--
things that depend.
Cool, more questions?
Good?
Yes.
>> AUDIENCE: I think you were doing all the editing in a different text
editing program.
Should we also download that?
>> GABRIEL GUIMARAES: Yeah, I like this text editor called TextMate.
And it's really good.
It's well suited to Ruby.
It colors things very neatly.
So TextMate, T-E-X-T. I'm going to put that, hold on--
>> I mean you can use gedit or anything you want.
But this is specific for Mac, and this is really neat because it puts all of
your files down there.
And in Ruby on Rails, you need to switch files a lot.
So it's many, many files just go from one file, jump to
one file or the other.
So TextMate is a very good one, but there are plenty out there.
More questions?
OK, yes?
>> AUDIENCE: Is there a mobile development through Ruby on Rails?
>> GABRIEL GUIMARAES: I've heard of things.
I haven't used them.
You could research more on that.
I'm not sure if there's any good thing out there.
OK, yes?
>> AUDIENCE: [INAUDIBLE]
>> GABRIEL GUIMARAES: Not Rails, probably Ruby array.
Open up a terminal window and type, "Ruby".
Yeah, probably, and then you just have to install Rails.
But if you're going to install the new Rails 4.0, which I highly recommend,
you should download Ruby 2.0.
That's the new one too.
And the new Rails 4.0 has something really cool that
it does to the assets.
It handles assets.
Assets again are images, CSS files, and JavaScript files.
So one really neat thing that Ruby on Rails does for you is all of those CSS
files that you have and everything--
it just bundles everything up into one huge file, with no spaces or anything,
to minimize the time the user needs to download that code from your server.
>> So when you see in your computer, it's going to have like 15 CSS files.
Or many, many different CSS files.
But at the end of the day, what Rails automatically does for you is it puts
everything together into one huge file so that it minimizes the request time.
That's really cool.
Yes?
>> AUDIENCE: [INAUDIBLE]
>> GABRIEL GUIMARAES: Exactly.
So, Google Maps integration.
That's a JavaScript API from Google.
So I just went to the Google website.
They have this Google Maps API and I downloaded the code and integrated it
into my view.
So what I needed to do there is I needed to get the
locations from the database.
That was done in the controller.
So I went to the controller--
where's the controller.
The controller looked like this.
Got all of the locations of the students, put all of that into a big
variable, a big list, that has all the locations.
>> And in the view, because the JavaScript API is something in the
view, right?
Because JavaScript runs within your HTML code, it's going to be sent to
the user's machine.
And in the view, I loaded all of that information into the Google API.
And it did all of that for me, which is really cool.
But if you want to use things in the back-end, and it's like a library, for
example, again--
the integration with Facebook.
That's something that many, many, many apps are using nowadays.
>> So have your integration with Facebook because it's so much easier to just
log in with Facebook than to create an account and blah, blah, blah.
Then you just use a gem and it's as simple as going to your gem file.
Gem file is a file called gem file in the source directory of your Ruby on
Rails project.
Just go there and add new gem .
And you look it up on Google.
There are many, many, many gems .
There's one that specifically does this for Facebook integration.
I'm not sure what the name of it.
Just Google it and you're going to find it.
OK, more questions?
Awesome, thank you for coming.