This course will be retired on April 30, 2018. We recommend "Ruby on Rails 5 Basics" for up-to-date content.
Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Start a free Basic trial
to watch this video
The application layout is basically a wrapper for the rest of a Rails application. This is the container where our view templates will be rendered. The current application layout needs to have some of its markup modified before the individual view templates can be addressed.
Links
- Foundation Documentation
- Foundation Grid Documentation - This is where we get the "row", "small-", "medium-", "large-*" and "columns" classes.
-
0:00
You'll notice here that I have two tabs open in my terminal,
-
0:06
and one of them I'm going to use to run the application,
-
0:12
and the other one I'll use just for typing in terminal commands.
-
0:16
So I just started up the application,
-
0:18
let me switch over and make sure that it is actually running.
-
0:26
Now, we want to switch over to sublime text, and
-
0:31
we want to get started on the markup.
-
0:33
First though, there is one bit of adminstrivia I want to take care of,
-
0:39
and that is in the get ignore file.
-
0:43
If you're on a Mac, like me, you'll want to add dot
-
0:49
DS underscore store to your get ignore file because
-
0:56
we don't want these DS store system files getting committed to our repo, so
-
1:01
we want to add it to our git ignore, and that will just ignore
-
1:06
any DS store files that end up there, and they won't get committed.
-
1:11
So just add dot DS store on a new line and that will ignore them.
-
1:17
If your using Windows or
-
1:19
Linux, you'll want to make sure that similar system files are ignored.
-
1:24
So I've saved that file, and now we want to
-
1:29
start our markup with the application layout,
-
1:35
and that's gonna be inside of app, views,
-
1:40
layouts, application.html.erb.
-
1:46
Now, if you're not familiar, the application layout is
-
1:51
basically a wrapper for the rest of a rails application.
-
1:56
So, if you look at something like to do lists or to do items,
-
2:01
you'll see a couple of different views in here, and these were covered
-
2:06
in previous lessons, but I just want to give you a quick refresher here.
-
2:11
You'll see something like index.html.erb, and that's actually the index
-
2:16
view for a particular model, in this case, to do lists.
-
2:21
This markup will appear where it says
-
2:27
yield inside of our application layout, so
-
2:31
all of our views elsewhere in the app will appear here.
-
2:35
Modifying the application layout will modify pretty much every
-
2:40
page in our app because it's modifying everything that is
-
2:44
wrapped around whatever is yielded in the application.
-
2:49
So with that in mind,
-
2:51
I want to rearrange a couple of things throughout the entire application.
-
2:57
First, I want my Flash messages to actually appear at
-
3:02
the top of my markup here, so I'm going to highlight this here,
-
3:10
I'm going to remove it, and then I'm going to come up here
-
3:15
just after the start of the body and paste that in there.
-
3:22
And this is pretty much unchanged from what rails already provides for
-
3:28
us, but we're going to do some styling here later on and
-
3:33
we're gonna do it using foundation, so we want to add a couple of
-
3:37
foundation classes that will actually style this for us.
-
3:42
So, I'm gonna leave the message type in here and
-
3:48
I just want to type in a few classes, and
-
3:53
those will be Flash alert box and text center.
-
3:58
And later on, when we're actually doing some styling,
-
4:03
there will be a little bit more apparent what those classes do.
-
4:07
Text center is fairly obvious, it will center the text.
-
4:12
Alert box will just add some alert styling.
-
4:17
Now, just below our message I want to add an anchor element,
-
4:25
and this anchor is going to lead to nowhere.
-
4:29
It's just going to be some JavaScript, and I'm gonna add the class close.
-
4:37
And what this anchor will do is add a button
-
4:42
which will allow us to dismiss any kind of alert messages or
-
4:48
Flash messages that pop up.
-
4:52
So I'll save that,
-
4:53
one thing I should point out is that I typed an HTML entity here called times.
-
4:58
That is just going to print an X,
-
5:02
so it's sort of like when you did multiplication in school and
-
5:05
you said this number times this number, and use an X as the symbol.
-
5:12
So that's all that is.
-
5:14
And I want to apply some classes that are provided to us through Foundation.
-
5:21
So first, I'm going to change this to say header.
-
5:32
Change header down here.
-
5:34
And I'm going to remove a couple things here.
-
5:38
Don't need that line break.
-
5:42
I don't want this to be a list anymore, so we need to actually remove the unordered
-
5:47
list and move all the list items here.
-
5:54
So I'm just removing these closing list items, and
-
5:59
then we need to remove the opening ones,
-
6:06
being careful to preserve these logged in and logged out links.
-
6:12
There we go.
-
6:14
And then I also don't want this to appear at all, so I'm going to remove that.
-
6:22
We don't actually need that headline element there.
-
6:28
So now I'm ready to add some foundation classes.
-
6:31
So inside of this header,
-
6:35
I'm going to apply the class row and global header.
-
6:43
Now the first one, row, is a foundation class,
-
6:49
and what this will do is, as it implies, create a new row,
-
6:55
and inside of that row we can add some columns.
-
6:59
So this will basically break up different sets of columns, and
-
7:04
you'll see this class, row, appear again later on.
-
7:08
We'll get to that very shortly here.
-
7:11
Now inside of this header, we're going to add a div,
-
7:18
and I want to close it down here
-
7:26
because this is actually going to be a set of columns.
-
7:32
In fact, this is just going to be one column represented by this div, but
-
7:36
I want it to span across several foundation columns,
-
7:43
and we're gonna add quite a few classes here, but I'll explain each one.
-
7:48
So first, we wanna add small-12,
-
7:53
then small-centered, then medium-8,
-
7:58
and medium-centered, and
-
8:02
then large-5 and large-centered,
-
8:07
and then, finally, the class columns.
-
8:14
Now, what does all this do?
-
8:15
Well, each one of these small, medium, and large, are how many columns
-
8:23
this particular div should span across at different responsive sizes.
-
8:28
Sow we could have just said small 12, and small centered,
-
8:34
and that would have let the divs span across 12 columns and center it.
-
8:39
Of course there are 12 columns in foundation, so
-
8:42
that means it will span across all columns.
-
8:45
And if we just let it at that and didn't add any of these additional classes,
-
8:50
then it would have span across 12 columns at small, medium, and large sizes.
-
8:55
But since foundation is a mobile first framework,
-
9:00
we can add that small 12 class first and
-
9:04
then we can additionally say if we want it to be different at larger sizes.
-
9:10
So working our way upwards at medium sizes.,
-
9:14
we want it to only span across eight columns, and then at the largest size,
-
9:19
we only want it to span across five columns.
-
9:23
The last class that we want to add is columns.
-
9:27
In foundation, that class, columns or column, will do exactly the same thing.
-
9:33
It's really just a stylistic thing,
-
9:35
so throughout this project we'll be typing columns, but
-
9:39
I just wanted to point that out, in case you're used to just typing column.
-
9:46
Now, that will just do the header.
-
9:48
We actually need to add some classes around the rest of our content,
-
9:54
so let's do that now.
-
9:59
And I'm gonna make some room to work here.
-
10:03
Move that up just so you can see what I'm doing.
-
10:07
And on this div, I want to remove content, and
-
10:11
instead I'm going to say, row, and then collapse,
-
10:17
and that's gonna create a new row, and it will make sure
-
10:22
that the columns actually span edge to edge when it's a small-12.
-
10:29
So let's create another div around here for
-
10:34
our columns, and I'll just tab that in, and
-
10:39
we want this to be exactly the same as what we have up here.
-
10:48
So I'll paste that in.
-
10:52
Okay, that looks good.
-
10:53
And then finally, again,
-
10:56
we'll use another HTML5 element, footer,
-
11:02
and similarly, write the class row,
-
11:07
then inside we'll add a div.
-
11:11
And then once again, we want all the same classes, so
-
11:15
we'll copy and paste that right there.
-
11:20
And there's one more class there that we want to add, and that's text center
-
11:26
because we want the text in our footer to be centered
-
11:30
just like in our Flash messages up here.
-
11:37
Now, there's some code that we want to add inside of our footer.
-
11:42
We want to show the settings link, which is basically
-
11:47
just the edit user path, if users are logged in.
-
11:53
So let's type that out now.
-
11:56
So we'll say, if logged in and
-
12:03
we'll end that there.
-
12:14
We want to display.
-
12:21
A link to.
-
12:27
And say settings, and it'll be the edit_user_path,
-
12:33
and we want to pass that the current_user.
-
12:38
So let me delete all this extra space here.
-
12:42
Save that out, and if we switch back to the browser and refresh the page here,
-
12:51
we should see that we're now using the foundation responsive columns.
-
12:56
So if I resize the browser, you can see that at mobile sizes,
-
13:04
our application will span edge to edge, which is exactly what we want.
-
13:08
It doesn't look too pretty now, but we'll change that soon, and
-
13:12
then as we get up to larger sizes, say on a tablet,
-
13:17
it will span a little bit wider, but not quite touching the edges.
-
13:23
And then finally, at desktop sizes, it will span across five columns.
-
13:30
So now we can switch back to our terminal and type git status, and
-
13:35
you'll see that we modified the git ignore and the application.html.erb layout.
-
13:43
Then we can type get commit dash an to add and
-
13:48
write our message, and
-
13:51
we'll say modify the application layout.
-
13:59
And then I can just type git push.
-
14:07
And it will push it to the design branch.
You need to sign up for Treehouse in order to download course files.
Sign up