Latest / CyberCode Academy / Course 37 - Building Web Apps with Ruby On Rails | Episode 3: Mastering Rails Scaffolding and Development
Transcript
- 0:00Speaker 1: Back in two thousand and five, there was this tech
- 0:03Speaker 1: demo that basically made the whole software world lose its
- 0:07Speaker 1: collective mind.
- 0:08Speaker 2: Yeah, it really was a watershed moment in software engineering.
- 0:11Speaker 1: Right because someone sat down and built a fully functioning
- 0:14Speaker 1: blog from absolute scratch in like what fifteen minutes. I mean,
- 0:18Speaker 1: that's barely enough time to drink a cup of coffee.
- 0:21Speaker 2: It truly was. And you know, before that specific demonstration,
- 0:24Speaker 2: web development was well, it felt like you were manually
- 0:27Speaker 2: wiring an old telephone switchboard, wow, just to get a
- 0:30Speaker 2: single web page to display like one line of text
- 0:33Speaker 2: from a database. So that demo promised unprecedented speed, but
- 0:37Speaker 2: more importantly, it promised empowerment for individual developers.
- 0:42Speaker 1: Today, we're doing a deep dive into exactly how that
- 0:45Speaker 1: magic works. Our mission is to recreate that exact sense
- 0:48Speaker 1: of speed and empowerment.
- 0:50Speaker 2: For you exactly. We're going to build a web application together,
- 0:52Speaker 2: step by step.
- 0:53Speaker 1: Entirely through audio. So we're calling our application Planter. It's
- 0:57Speaker 1: a tracker for plants and the people who love them
- 0:59Speaker 1: will serve as your audio tour guides, translating the code
- 1:03Speaker 1: and the command line interface into a really clear, vivid
- 1:06Speaker 1: mental model.
- 1:07Speaker 2: Which is an incredibly powerful way to internalize complex systems.
- 1:11Speaker 1: You know, oh for sure.
- 1:12Speaker 2: By removing all the visual clutter of a computer screen,
- 1:15Speaker 2: we can focus entirely on the underlying logic, the architecture,
- 1:19Speaker 2: and how data actually flows through the application.
- 1:22Speaker 1: I have to admit, though, starting with a completely blank
- 1:24Speaker 1: command line terminal is I mean, it's intimidating. Oh absolutely,
- 1:28Speaker 1: It's just you and a blinking cursor. If the web
- 1:30Speaker 1: browser is the steering wheel and dashboard of a car,
- 1:33Speaker 1: the terminal feels like popping the hood and just you know,
- 1:36Speaker 1: turning wrenches directly on the engine block. Okay, let's unpack this.
- 1:39Speaker 1: Where do we even begin without getting totally overwhelmed.
- 1:43Speaker 2: Well, the secret is that you do not actually build
- 1:45Speaker 2: the foundation yourself. You command the framework to build it
- 1:48Speaker 2: for you. Okay, So, based on our setup today, we're
- 1:51Speaker 2: using Ruby version two point seven point two and Rails
- 1:55Speaker 2: version six point one point zero. You just start by
- 1:58Speaker 2: typing three simple words into the terminal. Just three words, yep,
- 2:02Speaker 2: Rails new planter.
- 2:03Speaker 1: Okay, So I hit enter and suddenly the screen is
- 2:06Speaker 1: just flooded with text. I'm seeing tools like Yarn, webpacker, Puma.
- 2:12Speaker 1: I mean, I thought we were writing Ruby. What is
- 2:14Speaker 1: all this extra stuff installing on my machine?
- 2:16Speaker 2: That is a very fair reaction. I mean it looks
- 2:19Speaker 2: like a lot. It really does, but modern web applications
- 2:22Speaker 2: require a lot of moving parts to function correctly. Rails
- 2:27Speaker 2: is basically pulling together all those dependencies for you behind
- 2:30Speaker 2: the scenes.
- 2:30Speaker 1: But they're doing the busy work exactly.
- 2:32Speaker 2: Like yarn is a package manager. It goes out to
- 2:35Speaker 2: the Internet to gather up any JavaScript libraries you might
- 2:39Speaker 2: need for the front end user interface, and then Webpacker
- 2:42Speaker 2: acts like this industrial bundler. It compresses and organizes that
- 2:45Speaker 2: JavaScript so it loads quickly in a browser.
- 2:48Speaker 1: Right, and what about Puma.
- 2:49Speaker 2: Puma is the web server that will eventually listen for traffic.
- 2:53Speaker 2: So when you see the message that webpacker was successfully installed,
- 2:57Speaker 2: your foundation is completely set.
- 2:59Speaker 1: That's wild. The framework just built in entire directory for
- 3:02Speaker 1: our app, just like that. To get inside it, we
- 3:05Speaker 1: type cd planter, which stands for change directory, and if
- 3:09Speaker 1: we look around inside we see the core architecture of
- 3:11Speaker 1: our app, right, folders labeled models, views, and controllers.
- 3:17Speaker 2: Right, but right now it is just a skeleton.
- 3:20Speaker 1: Yeah, we have the empty rooms, but no furniture.
- 3:22Speaker 2: Exactly. So to start furnishing, we use a concept called scaffolding.
- 3:26Speaker 1: I love that term.
- 3:27Speaker 2: It's great, right. So back in the terminal we type
- 3:31Speaker 2: the RAILS generate scaffold command. We want to create our
- 3:35Speaker 2: first resource, the users of our app.
- 3:37Speaker 1: Okay, so we're building the people first.
- 3:39Speaker 2: Yes, we type rails generate scaffold person, and we specify
- 3:43Speaker 2: that a person should have an email and a name.
- 3:46Speaker 1: I find the term scaffolding so brilliant here because it's like, well,
- 3:50Speaker 1: it's like ordering a prefab house.
- 3:51Speaker 2: Oh, that's a perfect analogy.
- 3:53Speaker 1: Right, because instead of you laying down every single brick,
- 3:56Speaker 1: mixing the mortar and running the wires manually, the framework
- 3:59Speaker 1: drops the entire functional structure onto your lot. Instantly you
- 4:03Speaker 1: have the walls, the plumbing, and the electricity. In programming terms,
- 4:07Speaker 1: it generates the database, migration files, the model, the controller,
- 4:12Speaker 1: and all the interface views you need for basic cr functionality.
- 4:16Speaker 2: And for anyone unfamiliar with the acronyms, see RUD stands
- 4:19Speaker 2: for create, read, update and delete.
- 4:22Speaker 1: The essentials right.
- 4:23Speaker 2: It is the lifeblood of almost any data driven application.
- 4:27Speaker 2: RAILS just generated all the web pages required to create
- 4:30Speaker 2: a person, read their profile, update their email and delete
- 4:34Speaker 2: their account.
- 4:34Speaker 1: So our prefab person house is built. Let's turn on
- 4:38Speaker 1: the lights and see what it actually looks like.
- 4:39Speaker 2: Let's do it.
- 4:40Speaker 1: Back in the terminal, we type rail server to boot
- 4:42Speaker 1: up that Puma web server you mentioned earlier. It starts
- 4:45Speaker 1: running locally on port three thousand. Yep. I open my
- 4:48Speaker 1: web browser, navigate to local host point three zero, expecting
- 4:51Speaker 1: to see the beautiful new app, and boom.
- 4:53Speaker 2: The red screen.
- 4:54Speaker 1: I am greeted by a massive, aggressive, red air screen. Honestly,
- 4:59Speaker 1: it feels like turning the key in a brand new
- 5:01Speaker 1: car and immediately seeing a flashing check engine, Like like,
- 5:05Speaker 1: did I break it already?
- 5:06Speaker 2: I know that red screen is super alarming, but it
- 5:08Speaker 2: is not a crap. It's not No, it is actually
- 5:11Speaker 2: the framework communicating with you. It's actively protecting you. Okay,
- 5:14Speaker 2: how so, Well, if you read the text on the
- 5:17Speaker 2: error screen, it is gently reminding you that while you
- 5:21Speaker 2: use the scaffold command to prep the blueprints for the
- 5:23Speaker 2: people table, you haven't actually created that table in the
- 5:27Speaker 2: database yet.
- 5:27Speaker 1: Oh so it won't let me proceed, right.
- 5:30Speaker 2: It refuses to let you save data into avoid.
- 5:33Speaker 1: Uh okay, it says right there on the screen, run
- 5:36Speaker 1: pending migrations. Now, migration sounds like, you know, birds flying
- 5:41Speaker 1: south for the winter. What does that mean?
- 5:43Speaker 2: In the context of a database, A migration is essentially
- 5:46Speaker 2: a set of instructions that translates your Ruby code into
- 5:49Speaker 2: structural changes within the database. Okay, it is how you
- 5:53Speaker 2: tell the database to create a new spreadsheet like table
- 5:56Speaker 2: with columns for name and email. And the cool part
- 5:59Speaker 2: is you can click the button right on the red
- 6:01Speaker 2: screen or run rails dB dot migrate in your terminal.
- 6:05Speaker 1: So I run that command, refresh the browser, and we
- 6:08Speaker 1: have a heartbeat. That people page appears there.
- 6:10Speaker 2: It is.
- 6:11Speaker 1: It is completely bare bones with no fancy styling, but
- 6:14Speaker 1: it is functional. I click new person, type in my
- 6:18Speaker 1: name and email, and hit save. I mean, I just
- 6:21Speaker 1: created a profile for myself in an application we started
- 6:23Speaker 1: building like three minutes ago.
- 6:25Speaker 2: It's so fast. Now, switch your attention back to the
- 6:28Speaker 2: terminal where the server is running. It wasn't just sitting
- 6:30Speaker 2: idle while you were clicking around in the browser.
- 6:32Speaker 1: Yeah. Wait, so the terminal isn't just a place to
- 6:35Speaker 1: type commands to start the app. It's actually live broadcasting
- 6:38Speaker 1: the app's internal monologue exactly.
- 6:41Speaker 2: The terminal acts as a real time debugging log. When
- 6:45Speaker 2: you submitted that form to create your profile, the terminal
- 6:48Speaker 2: recorded the HTTP poct request. Oh wow, It logged that
- 6:52Speaker 2: the request was routed specifically to the create action of
- 6:56Speaker 2: the people controller. It even outputs the raw sequel in
- 7:00Speaker 2: statement that was fired into the database.
- 7:02Speaker 1: Okay, let's pause in trains like that for someone who
- 7:04Speaker 1: doesn't speak server architecture. An attP post request raw SQL.
- 7:09Speaker 1: That sounds like matrix code.
- 7:11Speaker 2: Huh it does. But think of the HTTP post request
- 7:15Speaker 2: as a digital envelope. When you click save. The browser
- 7:19Speaker 2: packaged your name and email into that envelope and mailed
- 7:23Speaker 2: it across the network to.
- 7:24Speaker 1: The server, and then the server opens it. Right.
- 7:27Speaker 2: The server opens the envelope, reads the contents, and then
- 7:30Speaker 2: uses SQL, which stands for Structured Query Language. SQL is
- 7:34Speaker 2: the specific vocabulary the server uses to command the database
- 7:37Speaker 2: to file that information away in the correct table.
- 7:40Speaker 1: Looking at these logs, it says complete it in thirteen milliseconds. Yeah,
- 7:44Speaker 1: that seems absurdly fast for packaging an envelope, mailing it,
- 7:49Speaker 1: opening it, translating it to SQL, saving it, and sending
- 7:52Speaker 1: a web page back to my screen.
- 7:53Speaker 2: It is incredibly fast, and you can literally trace the
- 7:56Speaker 2: full life cycle of your data millisecond by millisecond right
- 7:59Speaker 2: there in the term text.
- 8:00Speaker 1: That is fascinating. Okay, so we have users, but an
- 8:03Speaker 1: app called Planter needs plants. Before we build them, though,
- 8:06Speaker 1: we need to ensure our users provide valid data.
- 8:08Speaker 2: Yes, data integrity is crucial. So in our rails code,
- 8:11Speaker 2: we open the file representing our person model and add
- 8:14Speaker 2: a single word.
- 8:15Speaker 1: Yeah, validates, just one word.
- 8:17Speaker 2: It's one word. We use this rule to mandate that
- 8:20Speaker 2: an email address must be present, and the feedback cycle
- 8:24Speaker 2: here is instantaneous. Oh, I see the moment you save
- 8:27Speaker 2: that file. If you try to submit a profile without
- 8:30Speaker 2: an email in the browser, the process just halts and
- 8:33Speaker 2: displays a helpful error message right next to the empty field.
- 8:37Speaker 1: That's super clean. So with a user data protected, we
- 8:39Speaker 1: jump back to the terminal to generate our plants, we
- 8:42Speaker 1: run another scaffold command.
- 8:43Speaker 2: Right, yes, exactly.
- 8:44Speaker 1: We give the plant a string for its name, but
- 8:46Speaker 1: we also need it to belong to a person, so
- 8:49Speaker 1: use a reference.
- 8:50Speaker 2: And this brings us to the core of relational databases.
- 8:53Speaker 2: When generating the plant scaffold, telling the framework to include
- 8:56Speaker 2: a reference to a person triggers some serious magic behind
- 8:59Speaker 2: the scenes.
- 9:00Speaker 1: What kind of magic?
- 9:01Speaker 2: It builds a migration file that adds two critical constraints
- 9:04Speaker 2: to the database.
- 9:05Speaker 1: Null false and foreign key.
- 9:07Speaker 2: Let's step back for a second. Why is a relational
- 9:10Speaker 2: database such a breakthrough here? Like, why not just put
- 9:13Speaker 2: people and their plants into one giant flat spreadsheet and
- 9:17Speaker 2: call it a day.
- 9:18Speaker 1: Because a flat spreadsheet creates massive data anomalies. Okay, give
- 9:21Speaker 1: me an example.
- 9:22Speaker 2: Imagine you have a user named John Smith and he
- 9:25Speaker 2: owns fifty plants. In a spreadsheet, John Smith and his
- 9:29Speaker 2: email are copied onto fifty separate rows.
- 9:31Speaker 1: Oh, I see where this is going, right?
- 9:33Speaker 2: If John changes his email address, you have to find
- 9:36Speaker 2: and update all fifty rows manually. If you miss even one,
- 9:39Speaker 2: your data is corrupted.
- 9:41Speaker 1: That sounds like a nightmare.
- 9:42Speaker 2: It is a relational database solves this completely. John's profile
- 9:47Speaker 2: exists exactly once in the people table. Each of his
- 9:50Speaker 2: fifty plants sits in the plants table, and they simply
- 9:53Speaker 2: carry a tag a foreign key that points back to
- 9:56Speaker 2: John's single profile.
- 9:57Speaker 1: So you update his email once in all fifty plins,
- 10:00Speaker 1: plants instantly reflect the correct owner exactly. That makes perfect sense,
- 10:03Speaker 1: And those constraints you mentioned enforce the rules. So null
- 10:07Speaker 1: false tells the database to reject any plant that tries
- 10:10Speaker 1: to save without an owner. A plan must belong to
- 10:12Speaker 1: someone yep, and foreign key takes this step further right,
- 10:16Speaker 1: the database actively checks to ensure the owner actually exists
- 10:19Speaker 1: in the people table, like you cannot assign a plant
- 10:23Speaker 1: to person ninety number ninety nine if person ninety nine
- 10:25Speaker 1: does not exist.
- 10:26Speaker 2: Spot on. So we run rails dB dot migrate to
- 10:29Speaker 2: push those rules into the database structure. Then we return
- 10:33Speaker 2: to the browser to create a new.
- 10:34Speaker 1: Plant and that this is where we run into a
- 10:36Speaker 1: glaring user experience problem. Oh yeah, we can type in
- 10:39Speaker 1: the name of the plant, let's say a tomato, but
- 10:43Speaker 1: the field for the owner just asks for a person.
- 10:47Speaker 1: If you are the user typing a cryptic database ID
- 10:50Speaker 1: number like one or forty two into a blank textbox,
- 10:55Speaker 1: is well, it's a terrible experience. Humans remember names, not
- 10:59Speaker 1: database index numbers. It's awful.
- 11:01Speaker 2: Ux. To fix this, we have to change how the
- 11:03Speaker 2: form renders in the browser. Action view, which is the
- 11:07Speaker 2: part of the framework that handles what the user sees,
- 11:09Speaker 2: provides a tool called the select method.
- 11:11Speaker 1: Okay, so we take that plaintext box and replace it
- 11:13Speaker 1: with the select method, and it transforms the input into
- 11:16Speaker 1: an HTML drop down menu.
- 11:18Speaker 2: Exactly.
- 11:18Speaker 1: You can figure the drop down with two pieces of information, right,
- 11:21Speaker 1: the name you want to display to the human user
- 11:23Speaker 1: and the ID number you want to send back to
- 11:24Speaker 1: the database.
- 11:25Speaker 2: Right. It is the perfect bridge between a smooth user
- 11:28Speaker 2: experience and strict database requirements. You open the drop down,
- 11:31Speaker 2: you see your own name. You click it, but secretly,
- 11:34Speaker 2: but secretly, when you hit submit, the browser packages up
- 11:38Speaker 2: your numeric database ID into that HTTP post envelope, ensuring
- 11:44Speaker 2: the foreign key constraint is perfectly satisfied.
- 11:47Speaker 1: So sneaky. We apply a similar trick on the page
- 11:50Speaker 1: that displays the plant's details too. Instead of the screen
- 11:53Speaker 1: saying owned by person one, we update the code to
- 11:56Speaker 1: read plant dot person dot name much better, and we
- 12:01Speaker 1: wrap that code in a tool called linkedo, specifically using
- 12:04Speaker 1: the person path helper. This turns the name into a
- 12:07Speaker 1: clickable hyperlink that takes you directly to the owner's profile.
- 12:10Speaker 2: So now we're creating a web of interconnected data that
- 12:13Speaker 2: is easy to navigate. But this raises an important question.
- 12:16Speaker 1: Okay, well, seth, we have.
- 12:17Speaker 2: Successfully linked plants to people, but what happens when we
- 12:20Speaker 2: try to look at a person's profile and see a
- 12:22Speaker 2: list of all the plants they own.
- 12:24Speaker 1: Oh right, okay, let's try it. Pull up a person's
- 12:26Speaker 1: profile page. I want to list everything they are growing.
- 12:29Speaker 1: I add a small embedded Ruby tag to the HTML
- 12:31Speaker 1: file that simply asks the system to print out this
- 12:34Speaker 1: person's plants. I refresh the browser, fully expecting a nice,
- 12:37Speaker 1: neat list, and the application completely crashes. We get a
- 12:40Speaker 1: no method error undefined method plants per person.
- 12:44Speaker 2: Yes, And this is where we encounter another hidden superpower
- 12:49Speaker 2: of this framework, the error dashboard itself.
- 12:53Speaker 1: Okay, because normally errors are just a wall.
- 12:55Speaker 2: Of text exactly most programming languages just vomit a stack
- 12:59Speaker 2: trace onto this that looks like the matrix raining down
- 13:02Speaker 2: in pure text rails gives you an interactive diagnostic interface.
- 13:06Speaker 1: It really is incredibly detailed. It highlights the exact line
- 13:10Speaker 1: of code that failed, line fourteen. It shows the lines
- 13:13Speaker 1: of code above and below it for context. It displays
- 13:16Speaker 1: the request parameters, confirming that I was in fact trying
- 13:19Speaker 1: to look at person number one.
- 13:21Speaker 2: Amazingly, it also provides an interactive terminal console embedded directly
- 13:25Speaker 2: inside your web browser.
- 13:26Speaker 1: Inside the browser itself.
- 13:28Speaker 2: Yes, you do not have to guess what the data
- 13:30Speaker 2: looks like. You can literally type Ruby commands into the
- 13:33Speaker 2: browser window to interrogate the objects and debug the exact
- 13:36Speaker 2: moment the error occurred.
- 13:38Speaker 1: That's super cool.
- 13:39Speaker 2: You can ask the console does this person exist? It
- 13:41Speaker 2: answers yes. You ask can you show me their plants?
- 13:43Speaker 2: It returns an error.
- 13:44Speaker 1: What's fascinating here is why did it break? I mean,
- 13:46Speaker 1: we just spent several minutes meticulously setting up that foreign key.
- 13:50Speaker 1: The database absolutely knows that these plants belong to this person, right.
- 13:55Speaker 2: The issue is a disconnect between the database and the
- 13:57Speaker 2: application logic. The database knew about the relationship perfectly, but Ruby,
- 14:03Speaker 2: the programming language running the application logic, had no idea.
- 14:06Speaker 2: We never explicitly told the Ruby person model that it
- 14:09Speaker 2: was allowed to possess plans.
- 14:10Speaker 1: Ah, so they are speaking different languages and we have
- 14:13Speaker 1: to formally introduce them exactly. We open the person model
- 14:16Speaker 1: code and add one simple line has many dot plants.
- 14:19Speaker 2: We are formally defining the relationship for the programming language.
- 14:23Speaker 2: You save the file, return to the browser, and refresh.
- 14:26Speaker 2: The crash is gone.
- 14:27Speaker 1: The crash is gone, sure, but the result in the
- 14:29Speaker 1: screen is totally bizarre. Instead of seeing the word tomato,
- 14:33Speaker 1: I see this incredibly long, jumbled string of text active record,
- 14:37Speaker 1: dot associations, dot collection proxy. What in the world is
- 14:41Speaker 1: a collection proxy?
- 14:42Speaker 2: Hah yeah, it looks like gibberish. When you ask the
- 14:45Speaker 2: person profile for its plans, the system did not just
- 14:48Speaker 2: hand you a simple string of text. It handed you
- 14:51Speaker 2: a complex intermediate object. A collection proxy sits between your
- 14:56Speaker 2: code and the database results. Think of it as an
- 14:59Speaker 2: array line structure that contains many model instances.
- 15:03Speaker 1: Let's use an analogy to clarify that, because that's pretty abstract.
- 15:06Speaker 1: Imagine you go to an exclusive VIP event and you
- 15:09Speaker 1: ask to see the guest list. Okay, the collection proxy
- 15:12Speaker 1: isn't the guest list itself. It's the highly organized secretary
- 15:16Speaker 1: holding a thick folder of guest profiles. Yes, you can't
- 15:20Speaker 1: just tell the system to print the secretary. If you do,
- 15:23Speaker 1: you just get a physical description of the secretary, which
- 15:26Speaker 1: is that long active record string we just saw.
- 15:28Speaker 2: That is a perfect way to visualize it. If you
- 15:30Speaker 2: want the actual names of the guests, you have to
- 15:32Speaker 2: instruct the secretary to open the folder, go through the
- 15:34Speaker 2: profiles one by one. And read out the names aloud.
- 15:37Speaker 1: Got it in our code? We do that by iterating
- 15:41Speaker 1: through the folder using a method called each. We say, hey,
- 15:45Speaker 1: collection proxy for each plant inside your folder, print out
- 15:48Speaker 1: its name, I reload the page, and finally, the word
- 15:52Speaker 1: tomato appears beautifully on the screen.
- 15:55Speaker 2: Success. The core logic of the application is now perfectly wired.
- 16:00Speaker 2: The database constraints are satisfied, the Ruby models are communicating,
- 16:04Speaker 2: and the data is displaying awesome. Now we need to
- 16:07Speaker 2: elevate the application from feeling like a rigid database risk
- 16:10Speaker 2: into something that feels pleasant to navigate. Users should not
- 16:14Speaker 2: be forced to type URLs manually into the address bar
- 16:17Speaker 2: to get around right.
- 16:18Speaker 1: So, let's say we're looking at our user's profile and
- 16:20Speaker 1: we realize they are missing a plant. How do we
- 16:23Speaker 1: create a button on their profile that links directly to
- 16:25Speaker 1: the form to create a new plant. How do we
- 16:27Speaker 1: even know what the specific URL path for that form is?
- 16:30Speaker 2: Well, the framework provides a built in map for this.
- 16:32Speaker 2: Back in the terminal, you type the rails routes command.
- 16:35Speaker 2: This prints out every single valid URL path in your
- 16:37Speaker 2: entire application. It's handy, it is, but because that list
- 16:40Speaker 2: can get overwhelmingly long in a large app. We can
- 16:43Speaker 2: filter it by typing rails routes rep plant. We use
- 16:47Speaker 2: the pipe symbol to filter the results.
- 16:49Speaker 1: This pipe character, the vertical bar, appears frequently in software engineering.
- 16:54Speaker 1: Why is piping such a fundamental concept.
- 16:57Speaker 2: It represents a beautiful philosophy of system design originating from Unix,
- 17:01Speaker 2: chaining small dumb tools together to do complex.
- 17:05Speaker 1: Work small dumb tools.
- 17:07Speaker 2: Yeah, the railsport's command does one dumb thing. It dumps
- 17:11Speaker 2: a massive, unreadable list of text. Grep is a completely
- 17:14Speaker 2: separate tool that does another dumb thing. It searches text
- 17:18Speaker 2: for a specific word I see. By using the pipe symbol,
- 17:21Speaker 2: you are literally plumbing the output of the first tool
- 17:24Speaker 2: directly into the intake of the second tool.
- 17:26Speaker 1: That's incredibly elegant. So you filter the massive list, and
- 17:29Speaker 1: right there, clear as day, we see the helper method.
- 17:32Speaker 1: We need new plant path perfect. We drop that helper
- 17:35Speaker 1: into a link on our person's profile. We click it
- 17:37Speaker 1: and it takes us to the plant creation form. But
- 17:40Speaker 1: there is a tiny friction point here. What's that We
- 17:43Speaker 1: just came from person one's profile. When we arrived at
- 17:45Speaker 1: the new plan form, the dropdown menu doesn't know that
- 17:48Speaker 1: we have to manually open the drop down and find
- 17:50Speaker 1: person one all over again.
- 17:52Speaker 2: Ah yeah, we can eliminate that friction by passing parameters
- 17:55Speaker 2: in the URL. When we create the link on the
- 17:58Speaker 2: person's profile and attach a tiny piece of luggage to
- 18:01Speaker 2: the end of the web address, we append dot personed
- 18:05Speaker 2: one to the link.
- 18:06Speaker 1: Oh I love that. So when the link sends you
- 18:08Speaker 1: to the form, it hands the form that little piece
- 18:10Speaker 1: of luggage. The form opens, it sees the ID number
- 18:14Speaker 1: and automatically pre selects that specific person in the dropdown menu.
- 18:18Speaker 2: It is very smooth, but as developers we must always
- 18:21Speaker 2: consider edge cases. What if a user arrives at the
- 18:24Speaker 2: plant creation form from the main homepage rather than clicking
- 18:28Speaker 2: through a specific person's profile, right.
- 18:30Speaker 1: It will be any luggae attached to the URL.
- 18:32Speaker 2: Exactly by default, the dropdown might just auto select the
- 18:35Speaker 2: very first person in the database, which leads to accidental misassignments,
- 18:39Speaker 2: and we definitely.
- 18:40Speaker 1: Do not want someone accidentally assigning their prized tomato plant
- 18:44Speaker 1: to a complete stranger.
- 18:46Speaker 2: Definitely not. To protect against this, we revisit our select
- 18:49Speaker 2: dropdown code and add a simple configuration option include blank
- 18:54Speaker 2: pick a person nice Now if no one is pre
- 18:57Speaker 2: selected by the URL luggage. The form explicitly forces the
- 19:00Speaker 2: user to make a choice, eliminating ambiguity.
- 19:03Speaker 1: The flow is fantastic. Now you can click around, create
- 19:06Speaker 1: profiles and assigned plants, but visually, looking at the browser,
- 19:10Speaker 1: it still looks like a wireframe blueprint. We need some
- 19:12Speaker 1: global styling.
- 19:14Speaker 2: We do to implement global changes. We step outside the
- 19:17Speaker 2: specific view files for people on plants and we open
- 19:20Speaker 2: a file called application dot html dot EERB. This is
- 19:24Speaker 2: the master layout template, so.
- 19:25Speaker 1: Whatever HTML you put in this file wraps around every
- 19:28Speaker 1: single page in your application exactly.
- 19:30Speaker 2: It is the perfect place to put a navigation bar.
- 19:33Speaker 2: We add a navhtml tag at the very top with
- 19:35Speaker 2: links to our people index and our plants index. We
- 19:38Speaker 2: also add a header tag for the app's title planter, and.
- 19:41Speaker 1: Then we write a few lines of CSS to make
- 19:43Speaker 1: the navigation float to the right and the title float
- 19:45Speaker 1: to the left. We wrap the main content in a
- 19:47Speaker 1: main tag so our new header styles don't clash with
- 19:50Speaker 1: the rest of the page.
- 19:51Speaker 2: And with just those few styling tweaks, it suddenly feels
- 19:54Speaker 2: like a real application. But there is one final glaring
- 19:58Speaker 2: issue to resolve. What's left If you strip away all
- 20:01Speaker 2: the specific paths in the URL bar and navigate to
- 20:04Speaker 2: the very root of the app. Just local host tot
- 20:07Speaker 2: three thous zero. It still shows that default framework welcome screen.
- 20:11Speaker 1: Ah, right, we need to tell the system where the
- 20:14Speaker 1: front door of our application actually is. We open a
- 20:17Speaker 1: file called roads dot rb, which acts as the grand
- 20:21Speaker 1: traffic controller for the app. Inside, we add one single
- 20:24Speaker 1: line route to plants hashtag index.
- 20:28Speaker 2: And just like that, the default welcome screen is gone.
- 20:31Speaker 2: Going to the root URL now immediately greets you with
- 20:33Speaker 2: the main list of plants. We update the app title
- 20:36Speaker 2: in our master layout to link back to this route,
- 20:38Speaker 2: so clicking the logo always brings you home.
- 20:40Speaker 1: The application is officially complete, styled, and seamlessly navigable. If
- 20:45Speaker 1: you were listening to this and thinking, wow, that's a
- 20:47Speaker 1: massive amount of commands and syntax to remember, do don't worry.
- 20:51Speaker 2: Yeah, the insight here isn't to memorize the exact keystrokes.
- 20:54Speaker 1: Right. Let's take a breath and recap the core toolkit
- 20:56Speaker 1: we actually used. Surprisingly small, it really is.
- 21:00Speaker 2: We used rails new to build the initial architecture and
- 21:03Speaker 2: install all those background dependencies.
- 21:05Speaker 1: We used rails generate scaffold to instantly create the blueprints
- 21:10Speaker 1: for our models, views, and controllers.
- 21:12Speaker 2: We used rail server to boot up the application and
- 21:15Speaker 2: act as our real time debugging log.
- 21:17Speaker 1: We used railsdb dot migrate to push our structural changes
- 21:21Speaker 1: into the database, and.
- 21:22Speaker 2: Finally, we used rails writs to map out our navigation paths.
- 21:26Speaker 1: So let's test your new mental model with a quick
- 21:29Speaker 1: review exercise. We have built an app that tracks people
- 21:32Speaker 1: and their plans. Imagine you wake up tomorrow and decide
- 21:36Speaker 1: you want to add a brand new feature to this application,
- 21:39Speaker 1: watering schedule.
- 21:40Speaker 2: Oh that's a good one.
- 21:41Speaker 1: Based on everything we just discussed, what is the very
- 21:44Speaker 1: first command you would type into your terminal to start
- 21:47Speaker 1: building that feature.
- 21:48Speaker 2: I'll give you a second.
- 21:49Speaker 1: If you thought rails generate scaffold, you nailed it.
- 21:52Speaker 2: You absolutely nailed it. And you know this entire exercise
- 21:56Speaker 2: highlights a profound shift in how we think about building software.
- 22:00Speaker 2: We just constructed an entire application by mostly focusing on
- 22:04Speaker 2: wiring together relationships and sharing plants belong to people and
- 22:08Speaker 2: routing network traffic.
- 22:09Speaker 1: Yeah, we barely wrote any manual, line by line logical algorithms.
- 22:14Speaker 2: It was almost entirely high level.
- 22:16Speaker 1: Architecture, which raises a very provocative thought for the future
- 22:19Speaker 1: of technology, doesn't it.
- 22:20Speaker 2: It does. As artificial intelligence tools become increasingly proficient at
- 22:24Speaker 2: generating raw code, like writing the loops, the database queries,
- 22:28Speaker 2: the CSS styling.
- 22:29Speaker 1: Well, understanding this high level architecture become the only programming
- 22:33Speaker 1: skill that truly matters.
- 22:34Speaker 2: Exactly If an AI can write the granular code, perhaps
- 22:38Speaker 2: the human's sole job will be knowing how the pieces
- 22:41Speaker 2: of the puzzle connect together, which.
- 22:43Speaker 1: Circles us perfectly. Back to that legendary two thousand and
- 22:46Speaker 1: five tech demo we started with. The magic of that
- 22:48Speaker 1: moment wasn't that the developer typed incredibly.
- 22:51Speaker 2: Fast, No, not at all.
- 22:52Speaker 1: The magic was that they'd utilize a framework that abstracted
- 22:57Speaker 1: away all the tedious, repetitive coding, leaving them entirely free
- 23:00Speaker 1: to focus on the architectural design of the system. And
- 23:03Speaker 1: today you just experienced that same magic, building your own
- 23:07Speaker 1: conceptual mental model from the ground up. Thanks for diving
- 23:10Speaker 1: deep with us. Keep exploring those architectures and we will
- 23:13Speaker 1: catch you on the next one.