key: cord-0061492-8nppdirq authors: Notodikromo, Adam title: Building the Timeline date: 2020-10-25 journal: Learn Rails 6 DOI: 10.1007/978-1-4842-6026-5_6 sha: 4c2ed6cb987bb3e5b9000805849065e24ba59502 doc_id: 61492 cord_uid: 8nppdirq Timelines are newish inventions. According to the dictionary, a timeline is “a collection of online posts or updates associated with a specific social media account.” And that is what we will build in this chapter. See Figure 6-1. The timeline is a fundamental part of any social media app. There, users can see anyone's updates (an activity known as stalking), reply to any of them (commenting), or post an update themselves (posting). In addition, we will skin the timeline dark because the dark mode is currently the trend. No one uses social media that doesn't follow the trend, right? While building our timeline, you will also learn how to test our views à la carte (that's a cool way no one used to say unit testing). You will also learn how to do request testing, where we test all the way down from the router to rendering the view. Indeed, testing is something the previous chapter skipped. But don't worry, being the good software engineers that we are, we will consider testing a first-class citizen. So, this chapter will cover all the necessary testing techniques commonly employed by software engineers. First, let's keep in mind that there are two types of timeline we will build. The first one is the personal timeline, which reflects updates belonging solely to a user. The second one is the mass timeline, which contains all the updates made by both the signed-in user and the accounts they follow. authenticate :user do resources :timelines, only: [:index, : show] end end With that, we are done preparing the controller and the router. If we look back at our home page, we can see that a navigation bar is attached to the top of the page. However, it is in the template instead of in the layout. If we are to use the same application layout for the timeline, a navbar needs to be manually rendered on both the index and show pages, which doesn't feel so DRY. Our timeline will also use a dark mode skin, which requires a different design altogether. Using the application layout, how can we alter the coloring? Using yield and content_for to specify additional classes on the body tag feels quite indecorous, doesn't it? See Figure 6 -2. Chapter 6 Building the timeline Instead, let's create a new template. Let's call it member, which is used only for rendering pages mainly for logged-in users-which is why it's named member. We could name the layout timeline, but what if in the future we wanted to use it to render any nontimeline page such as a settings page to use the same look and feel? It's essential to name a layout as inclusively as possible. Note there are only two hard things in computer science: cache invalidation and naming things. Let's start making the layout. First, considering that all of our layouts currently have repeating head tags, let's DRY them out. Let's create the layouts/_header.html.erb partial and add the code shown in Listing 6-3. ' %> <%= evil_icons_sprite %> Then, let's replace entirely any head block with the code to render the header partial. Let's start with the application layout, as shown in Listing 6-4. After that, let's do the same for the session layout, as shown in Listing 6-5. Listing 6-5. DRY-ing the Head Tag in the session Layout