Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Introduction to Ruby on Rails 7!
You have completed Introduction to Ruby on Rails 7!
Preview
Give your app a custom landing spot. Build a home page and configure your routes so that visitors land here by default when they hit your app’s root URL.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Okay, so in this video, we're gonna style
this homepage, we're mainly just gonna add
0:00
some buttons, we're gonna add some logic
to make sure the user is signed in and
0:04
all that crap, and
then we'll see what's going on afterwards.
0:07
So what I'm gonna do is just go to this
and I'm gonna show you everything I do so
0:10
you can actually have a see as well,
0:13
because I don't want you
to lose out on everything.
0:15
So I'm gonna copy this code
from my already source code and
0:17
I'm gonna go to app views home index and
I'm gonna copy this in.
0:21
Now let's have a look, we have a style
sheet for index, have we already got that,
0:25
no, we haven't got that.
0:28
So let's create a style
sheet called Index CSS,
0:30
now let's go back to this Index HTML DRB,
then we have a row notice,
0:33
column 60 column content container,
text content.
0:38
So we have some text here,
then we say if user is signed in,
0:43
if current user tree present view my tree,
0:47
else create your own tree, and
else create your own tree.
0:50
So basically we're saying if
the user is signed in and
0:56
then that's everything, and then we're
saying if the user is signed in and
0:59
the user has a tree, then you have
a button called view my tree.
1:04
If they don't have a tree, then we say
create your own tree, and if they're not
1:08
signed in, then we say create your own
tree, because if they're not signed in,
1:12
then they have to have,
then they won't have a tree.
1:16
So then let's save this file and let's see
what happens, okay, so it actually works.
1:19
It works pretty well, but I'm still gonna
add some styling just to make it better,
1:26
so I'm gonna go here, index CSS and
copy it to this index CSS, perfect.
1:33
And then let's see what it looks like,
should be looking a little bit better,
1:39
yeah, perfect, that's a bit nicer.
1:42
So there we go, it takes us to our tree,
if I delete this tree,
1:44
then I go back, it should say create
your own tree, but it doesn't.
1:48
Okay, so now it says create your own link
tree because I just deleted the one that I
1:53
have, so
now we've styled the homepage, but
1:56
there's something really
important that we have to do.
1:58
And the really important thing that we
have to do is to go to controllers,
2:01
trees controller, and in the new method,
we're just gonna add this code.
2:04
So we're saying if the current user has
already a tree, then you say you already
2:08
have a tree assigned to you, and
then you redirect to their tree.
2:13
But if they don't,
then you can actually show the form, so
2:16
this is gonna stop the user
from creating two trees,
2:19
we don't want that to happen because
this is gonna mess up our logic.
2:22
So create your own tree,
then I'll create it, next,
2:26
Instagram, add the Instagram dark mode,
great,
2:30
then what I'm gonna do is go to the URL
and try and create another one.
2:33
As you can see, it doesn't let me
go to the URL when I type in new,
2:37
it just redirects me to my all
to the tree that I already have.
2:42
So that's absolutely perfect,
that's what I wanted to do,
2:46
the homepage is now styled,
task completed.
2:49
Let's go.
2:51
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up