Latest / CyberSecurity Summary / Build A SaaS App in Rails 7
Transcript
- 0:00Speaker 1: Have you ever paused, you know, to really think about
- 0:03Speaker 1: what it takes to build the software as a service
- 0:06Speaker 1: a sauce app from the ground up.
- 0:09Speaker 2: Yeah, it's It's definitely more than just.
- 0:11Speaker 1: Coding, right exactly, It's about architecting something wow.
- 0:14Speaker 2: Robust, scalable, user friendly, the whole package.
- 0:18Speaker 1: So today we're doing a deep dive. We've got this
- 0:20Speaker 1: fantastic source, a really comprehensive guide on building sauce with
- 0:25Speaker 1: Ruby on Rails seven.
- 0:27Speaker 2: And our mission really is to cut through all the complexity.
- 0:31Speaker 2: We want to pull out those key nuggets of knowledge,
- 0:33Speaker 2: look at the modern tools, the best practices, you know,
- 0:36Speaker 2: what makes Rails such a powerhouse for this kind of development.
- 0:39Speaker 1: Right, and show you how to navigate it all without
- 0:41Speaker 1: feeling well completely overwhelmed.
- 0:43Speaker 2: Get ready for some aha moments, because we're going to
- 0:46Speaker 2: demystify what goes into a production ready sauce app.
- 0:49Speaker 1: Okay, let's start right at the beginning. Then laying the foundation.
- 0:52Speaker 1: Rails has this famous philosophy convention over configuration. For folks
- 0:57Speaker 1: listening who may be no development, what's the real like
- 1:00Speaker 1: strategic edge you get from that when you're kicking off a.
- 1:02Speaker 2: Sauce It's all about speed initial velocity. Rails is well,
- 1:07Speaker 2: it's opinionated about speed. It hands you this pre defined
- 1:10Speaker 2: logical structure right away. Your app canfig dB test folders,
- 1:14Speaker 2: so you get productive almost instantly.
- 1:16Speaker 1: Ah, so you're not stuck debating file structures for days exactly.
- 1:20Speaker 2: You run Rails new and you've basically got a working
- 1:23Speaker 2: app skeleton ready for a Hello World pretty much out
- 1:27Speaker 2: of the box. It lets you focus on your business problem,
- 1:30Speaker 2: not the framework.
- 1:31Speaker 1: Setup that makes sense moves a lot of that initial churn.
- 1:34Speaker 1: And when you are spinning up that new app, what
- 1:36Speaker 1: are some of those first big setup choices, the ones
- 1:39Speaker 1: that really mark the difference between a quick demo and
- 1:42Speaker 1: something you'd actually deploy.
- 1:43Speaker 2: Okay, first up database, This trips people up. Sometimes Rails
- 1:48Speaker 2: defaults to skoy three, which is fine, super simple for
- 1:50Speaker 2: getting started.
- 1:51Speaker 1: But not for production.
- 1:53Speaker 2: Generally, No, for real sauce, you'll almost certainly want Postgres School.
- 1:56Speaker 2: It's just more robust handles, concurrent users, better advanced features
- 2:00Speaker 2: like Jason in b stuff.
- 2:02Speaker 1: You'll need later, so you'd specify that right at the start.
- 2:04Speaker 1: YEP Rails New year app database postcrescool tells Rails what
- 2:09Speaker 1: you intend to use from day one.
- 2:10Speaker 2: Okay, database sorted. What about managing the code itself, especially
- 2:14Speaker 2: if you have a team.
- 2:15Speaker 1: Well, get is absolutely fundamental. That's probably obvious to most devs,
- 2:19Speaker 1: but for Sauce. Its role in smooth team workflows, feature branching,
- 2:23Speaker 1: quick rollbacks when things go wrong. It's crucial for maintaining speed.
- 2:27Speaker 2: Insanity, and you'd host that somewhere like GitHub right.
- 2:30Speaker 1: GitHub, bitbucket. Essential for collaboration and especially for keeping your
- 2:34Speaker 1: code private.
- 2:35Speaker 2: Got it? Now? Inside that new Reils app, there's the
- 2:38Speaker 2: gem file. What are the sort of must have gems
- 2:41Speaker 2: included right away? What problems are they solving?
- 2:44Speaker 1: The gem file is like your recipe. You'll see pg
- 2:46Speaker 1: in there if you chose postcres school. That's the connector.
- 2:49Speaker 1: Puma is your web server handles the actual requests. It's fast,
- 2:53Speaker 1: concurrent and a really important one now is import mafrails.
- 2:56Speaker 2: What's the deal with that?
- 2:57Speaker 1: One?
- 2:57Speaker 2: Sounds modern?
- 2:58Speaker 1: It is? It lets you use modern JavaScript yes modules
- 3:01Speaker 1: directly in the browser without needing a complex build step
- 3:04Speaker 1: like webpack or as build. It really simplifies front end
- 3:08Speaker 1: asset management. Big win for developer experience and styling. That's
- 3:12Speaker 1: gotten simpler too, hasn't it.
- 3:13Speaker 2: Oh yeah, tailwind CSS is basically built in now with
- 3:16Speaker 2: Rail seven. It's a utility first CSS framework makes styling
- 3:21Speaker 2: fast and consistent without writing tons of custom CSS. You
- 3:24Speaker 2: build styles writing your HTML.
- 3:26Speaker 1: Okay, so you've run Rails new, configured a few things.
- 3:29Speaker 1: The source really stresses how fast you get something working.
- 3:32Speaker 1: Can you walk us through that?
- 3:33Speaker 2: Yeah, it's pretty neat. You run Rails new, then Rail Server,
- 3:36Speaker 2: and boom you've got a default Rails welcome page in
- 3:40Speaker 2: your browser. Minutes tops just like that. Then the guide
- 3:44Speaker 2: usually shows you making a tiny change at a route,
- 3:47Speaker 2: a super simple controller action to display your own custom
- 3:50Speaker 2: Hello World. It just hammers home how quick that feedback
- 3:53Speaker 2: loop is with rails rapid iteration.
- 3:56Speaker 1: Okay, let's talk. Testing often feels like a chore, But
- 4:00Speaker 1: why is it so critical, especially for size right from
- 4:02Speaker 1: the get go right.
- 4:03Speaker 2: It's not just about finding bugs today, it's about building confidence.
- 4:07Speaker 2: It's a safety net so when you refactor later or
- 4:11Speaker 2: add new features, you can deploy without constantly worrying you
- 4:15Speaker 2: broke something else. It actually speeds up long term development
- 4:18Speaker 2: because you move faster when you're not afraid to change things.
- 4:21Speaker 1: That's a great way to put it in. There are
- 4:22Speaker 1: different kinds of tests.
- 4:24Speaker 2: Right, Absolutely, you've got your model tests or unit tests,
- 4:26Speaker 2: so they check small pieces in isolation, make sure a
- 4:29Speaker 2: specific calculation is right for example. Then view tests and
- 4:33Speaker 2: the big ones system tests.
- 4:36Speaker 1: What does system tests do?
- 4:37Speaker 2: They use tools like Capybara to actually simulate a user
- 4:41Speaker 2: interacting with your app in a browser, clicking buttons, filling forms,
- 4:44Speaker 2: the whole flow.
- 4:45Speaker 1: Ah, so they test the whole stack together exactly.
- 4:48Speaker 2: They're powerful, but they're also slow.
- 4:50Speaker 1: To run, okay, so there's a trade off.
- 4:52Speaker 2: Definitely, you use system tests for your most critical user paths,
- 4:55Speaker 2: sign up, core feature usage, for edge cases or specific
- 5:00Speaker 2: controller logic, you rely on faster controller or unit tests
- 5:03Speaker 2: to get quick feedback makes sense.
- 5:05Speaker 1: Any specific testing tools that are really indispensable here.
- 5:08Speaker 2: I definitely mentioned simple cough. It shows your test coverage
- 5:12Speaker 2: literally highlights which lines of code your tests are.
- 5:14Speaker 1: Hitting, so you know what's not being tested precisely.
- 5:18Speaker 2: And the other big one is VCR.
- 5:19Speaker 1: VCR like the old video takes hah.
- 5:22Speaker 2: Yeah, the name's a bit retro, but it records external
- 5:25Speaker 2: API calls like to stripe or get hub the first
- 5:28Speaker 2: time your test runs them. Then on subsequent runs, it
- 5:32Speaker 2: just plays back that recorded response.
- 5:34Speaker 1: Ah, so your tests don't actually hit the live API.
- 5:37Speaker 2: Every time exactly makes tests way faster, more reliable, and
- 5:40Speaker 2: you can even run them offline. Huge time saver, especially
- 5:43Speaker 2: for APIs that change or have right limits brilliant.
- 5:45Speaker 1: And to run all these tests automatically, that's continuous integration,
- 5:49Speaker 1: right yeap.
- 5:50Speaker 2: CI services think Circle Ci, Travis CI, Semaphore, GitHub actions.
- 5:54Speaker 2: They run your full test suite automatically. Every time you
- 5:56Speaker 2: push code, you get immediate feedback did your change break anything?
- 6:00Speaker 2: Crucial for team velocity and keeping the codebase healthy.
- 6:03Speaker 1: Okay, shifting gears a bit. Users can't have a songs
- 6:06Speaker 1: without them. How do you start setting up a solid
- 6:08Speaker 1: user system in rails?
- 6:10Speaker 2: Users are everything? Yeah, it starts with a user model.
- 6:13Speaker 2: You add attributes you need, name, time zone, maybe rules later.
- 6:17Speaker 2: A really important detail, often overlooked early on, is adding
- 6:20Speaker 2: a hasheet or UUID.
- 6:22Speaker 1: Why is that important?
- 6:23Speaker 2: It's mainly for security and cleaner URLs. Instead of seeing
- 6:27Speaker 2: users one users two in the URL, which someone could
- 6:30Speaker 2: guess or iterate.
- 6:31Speaker 1: Through trying to find other users data.
- 6:34Speaker 2: Right, a UID gives you something like user say three
- 6:37Speaker 2: B seven C it's nonsequential, unpredictable, much safer, and Rail's
- 6:42Speaker 2: database migrations handle adding these columns and changing your database
- 6:46Speaker 2: schema really smoothly. That's a core strength.
- 6:48Speaker 1: Okay, And for actually logging users in authentication is building
- 6:52Speaker 1: your own login system still a thing people do.
- 6:54Speaker 2: Please please don't. Rolling your own off is notoriously hard
- 6:57Speaker 2: to get right. Security is complex, So what's the standard approach?
- 7:00Speaker 2: Devise It's a gem, It's been around forever, it's battle tested.
- 7:04Speaker 2: It handles sessions, cookies, password resets, confirmations, the works, and
- 7:08Speaker 2: it gives you basic views you can customize using device,
- 7:11Speaker 2: saves you a massive amount of time and prevents countless
- 7:13Speaker 2: security headaches.
- 7:14Speaker 1: Good advice. So users can log in. Yeah, but then
- 7:18Speaker 1: you often need roles right, like admins versus regular users.
- 7:22Speaker 1: How's that handled right?
- 7:23Speaker 2: So first you need the basic flows sign in, sign out,
- 7:26Speaker 2: sign up, make sure you have clear feedback using rails
- 7:29Speaker 2: flash messages. User invites are also common, especially for team
- 7:32Speaker 2: based apps. For roles themselves, a gem called rollifies really popular.
- 7:37Speaker 2: It lets you associate roles you define them like dot
- 7:40Speaker 2: admin or dot member with your users.
- 7:42Speaker 1: Okay, so user has a role.
- 7:44Speaker 2: Yep, and then you need to connect that role to
- 7:46Speaker 2: what they're allowed to do.
- 7:47Speaker 1: That's authorization and how do you manage that? Is there
- 7:50Speaker 1: standard way?
- 7:51Speaker 2: Can can can is the go to gem here. It's
- 7:54Speaker 2: incredibly powerful because it lets you define all your authorization
- 7:58Speaker 2: roles in one central place, usually a file called ability dot.
- 8:01Speaker 1: RB one file for all permissions.
- 8:03Speaker 2: Yeah, pretty much. It keeps things really organized.
- 8:05Speaker 1: How fine grained can you get with those rules?
- 8:08Speaker 2: Very you define can or cannot rules, you combine actions
- 8:11Speaker 2: like read dot create, dot update, dot manage, which is
- 8:15Speaker 2: like a wild card with specific models. So you could
- 8:17Speaker 2: say a user can manage their own projects, but they
- 8:20Speaker 2: can read projects belonging to their team.
- 8:23Speaker 1: Ah okay, very specific exactly.
- 8:26Speaker 2: And if someone tries to do something they're not allowed
- 8:28Speaker 2: to can can can helps you catch that and redirect them,
- 8:31Speaker 2: maybe show an access denied message.
- 8:34Speaker 1: And obviously you need to test all of this thoroughly.
- 8:37Speaker 1: The log ins, the roles, the permissions absolutely critical.
- 8:40Speaker 2: You'd use a mix of tests here. Controller specs are
- 8:43Speaker 2: good for checking the logic does this role get redirected correctly?
- 8:47Speaker 2: And system specs are essential for testing the full user experience.
- 8:50Speaker 2: Can a user actually sign up, log in and access
- 8:53Speaker 2: the things they should be able to access.
- 8:54Speaker 1: Right makes sense. Okay, let's dive into the core business logic,
- 8:58Speaker 1: the real meat of the application. The source mentioned scaffold
- 9:01Speaker 1: quite a bit. Rails G scaffold. What is that and
- 9:05Speaker 1: why is it highlighted? Ugh scaffolding. This is where rails
- 9:08Speaker 1: can feel like magic sometimes, especially when you're starting. It's
- 9:11Speaker 1: a generator command. You run rails G scaffold stand up,
- 9:15Speaker 1: for example, and it instantly creates the model, the database, migration,
- 9:19Speaker 1: the controller with all the basic actions index, show, new, create, edit, update,
- 9:25Speaker 1: destroy the views for each action and basic tests.
- 9:29Speaker 2: Wow. Okay, the whole cru setup in one command.
- 9:32Speaker 1: Exactly, crud, create, read, update, delete. It gives you a
- 9:36Speaker 1: fully working interface for managing that stand up object in minutes.
- 9:40Speaker 1: Huge shortcut for getting basic features up.
- 9:42Speaker 2: But it's not the final code, right. You don't just
- 9:44Speaker 2: deploy the scaffold output.
- 9:45Speaker 1: Oh definitely not. Think of it as a starting point,
- 9:47Speaker 1: a really, really good starting point. You almost always need
- 9:50Speaker 1: to customize the generator code, change the forms, tweak the
- 9:53Speaker 1: controller logic, adjust the views. But it saves you from
- 9:56Speaker 1: writing all that boilerplate yourself. It's you maybe eighty percent there.
- 10:00Speaker 2: Or fast okay, so you scaffold then customize using our
- 10:03Speaker 2: stand up tracker example. What are some key business models
- 10:06Speaker 2: or patterns you'd build on top of that. Well, one
- 10:08Speaker 2: neat concept the source mentions is tracking the current date
- 10:12Speaker 2: using RAILS sessions and maybe a dedicated controller. The app
- 10:16Speaker 2: can remember which date the user is looking at.
- 10:18Speaker 1: So if I navigate away and come back, I'm still
- 10:21Speaker 1: looking at yesterday's stand ups exactly.
- 10:23Speaker 2: It provides context across the application, very useful for something
- 10:27Speaker 2: like a daily stand up tracker.
- 10:29Speaker 1: And what about relationships like users belonging to teams?
- 10:32Speaker 2: That's a classic RAILS pattern has many through You'd have
- 10:36Speaker 2: user model, a team model, and a team membership model.
- 10:38Speaker 1: In between that links them the join table.
- 10:41Speaker 2: Right, it makes it easy to ask what teams does
- 10:43Speaker 2: this user belong to user dot teams? Or who are
- 10:47Speaker 2: the members of this team team dot users? Very clean.
- 10:51Speaker 2: You could also use similar patterns for things like static lookups,
- 10:53Speaker 2: maybe using enom for days of the week or something.
- 10:56Speaker 1: Got it and I saw something interesting about tasks single
- 10:59Speaker 1: table in Harrodan's STI. What's that about?
- 11:02Speaker 2: Ah STI? It's a clever database pattern. Imagine in our
- 11:07Speaker 2: stand up app you have different types of tasks, things
- 11:09Speaker 2: you did, things you plan, Toto, and maybe blockers.
- 11:13Speaker 1: Okay, three distinct types.
- 11:14Speaker 2: Instead of creating three separate database tables DIDs Toto's blockers,
- 11:19Speaker 2: you use one tasks table and you add a special
- 11:22Speaker 2: type column to that table. Rails uses this column to
- 11:25Speaker 2: know which class each row represents, did Toto or blocker?
- 11:29Speaker 1: So they all live in one table, but your code
- 11:30Speaker 1: treats them as different classes exactly.
- 11:33Speaker 2: It's great for models that share a lot of common
- 11:35Speaker 2: attributes but have some distinct behaviors. Keeps your schema simpler.
- 11:39Speaker 1: Very cool now, making all this feel dynamic and interactive.
- 11:43Speaker 1: Hot Wire seems to be a big deal in Rails seven.
- 11:46Speaker 1: What is it?
- 11:47Speaker 2: Hot Wire is huge. It's basically a collection of technologies
- 11:51Speaker 2: Turbo stimulus, JS and strata for mobile designed to give
- 11:54Speaker 2: you that fast interactive SPA.
- 11:56Speaker 1: Like field SBA being single page application. Right.
- 12:00Speaker 2: But here's the kicker. You get that feel without writing
- 12:03Speaker 2: much custom JavaScript. That's the revolutionary part for many Rails devs.
- 12:06Speaker 1: How does that work? No JavaScript framework needed largely. No.
- 12:10Speaker 2: Hot wire sends HTML over the wire, not Jason. It
- 12:13Speaker 2: leverages the server to render HTML fragments and then uses
- 12:16Speaker 2: clever techniques to update the page.
- 12:18Speaker 1: Okay, break that down. What does turbo do.
- 12:19Speaker 2: Turbo has a few parts. Turbo drive intercepts, link clicks
- 12:23Speaker 2: and form submissions. Instead of a full page reload, it
- 12:27Speaker 2: fetches the new page in the background and cleverly swaps
- 12:30Speaker 2: out just the body or specific parts. Makes navigation feel instant.
- 12:34Speaker 1: Okay, faster page changes. What about real time updates like
- 12:38Speaker 1: seeing a teammate stand up appear without refreshing.
- 12:41Speaker 2: That's turbo streams. It uses web sockets to push small
- 12:45Speaker 2: HTML changes directly from the server to all connected clients.
- 12:48Speaker 2: Someone saves the stand up, a turbostream message goes out
- 12:51Speaker 2: and bam, it appears on everyone else's screen.
- 12:53Speaker 1: And Turbo frames.
- 12:54Speaker 2: Turbo frames let you designate specific sections of your page.
- 12:58Speaker 2: Turbo frame tags as independent updatable Click a link inside
- 13:02Speaker 2: a frame and only that frame's content gets replaced. Great
- 13:05Speaker 2: for things like editing a single item in a list
- 13:07Speaker 2: without reloading the whole list.
- 13:09Speaker 1: And you can still use JavaScript if you need to
- 13:11Speaker 1: for things like date pickers.
- 13:13Speaker 2: Absolutely, that's where stimulus js comes in. It's a modest
- 13:16Speaker 2: JavaScript framework that connects JavaScript controllers to HTML elements using
- 13:21Speaker 2: data attributes the source shows integrating a JavaScript date picker
- 13:25Speaker 2: like flat picker stimulus handles the interaction and then maybe
- 13:29Speaker 2: triggers a turbo request to update the page content based
- 13:32Speaker 2: on the selected date. They work together beautifully.
- 13:35Speaker 1: So putting it all together, the stand up app can
- 13:37Speaker 1: show stand ups based on different filters.
- 13:39Speaker 2: Yeah, you can easily build views that show your stand
- 13:42Speaker 2: ups or all stand ups for a specific team, or
- 13:45Speaker 2: all stand ups from a particular user on their profile page. Rails,
- 13:49Speaker 2: routing and controllers handle the data fetching, and hot wire
- 13:52Speaker 2: makes the presentation dynamic and fast.
- 13:54Speaker 1: Okay, moving beyond the core UI in models, let's talk
- 13:57Speaker 1: robustness and integrations objects. You call them the secret sauce.
- 14:02Speaker 1: Why are they so important?
- 14:03Speaker 2: AI? Yeah, secret sauce might be a bit much, but
- 14:05Speaker 2: they are really helpful for keeping your code clean as
- 14:07Speaker 2: the app grows. The core idea is to prevent fat
- 14:11Speaker 2: controllers or fat models where you cram way too much
- 14:14Speaker 2: business logic into those default rails classes.
- 14:16Speaker 1: So you pull logic out exactly.
- 14:19Speaker 2: You create dedicated Ruby classes service objects that handle one
- 14:23Speaker 2: specific business process or action like create user process payment.
- 14:28Speaker 2: Since stand up reminder, it makes the code much easier
- 14:30Speaker 2: to understand, test and maintain. You know exactly where to
- 14:34Speaker 2: look for the logic related to creating a user.
- 14:37Speaker 1: Are their best practices for writing them? Yeah?
- 14:39Speaker 2: Definitely. A common one is to have just one public
- 14:43Speaker 2: method often called dot call, makes its purpose clear, keep
- 14:47Speaker 2: dependencies internal or pass them in, and crucially return something meaningful,
- 14:52Speaker 2: not just true or false.
- 14:53Speaker 1: What kind of meaningful object?
- 14:55Speaker 2: Maybe a simple struct or an immutable struck that indicates
- 14:58Speaker 2: success and carries the results object like the newly created
- 15:01Speaker 2: user or any errors that occurred. Gives you much more
- 15:04Speaker 2: context than a boolean.
- 15:05Speaker 1: Can you give a concrete example?
- 15:07Speaker 2: Sure, the source uses a new registration service. When the
- 15:10Speaker 2: user signs up, this one service might coordinate several steps.
- 15:13Speaker 2: Create the hat record, create a user, maybe create a
- 15:15Speaker 2: striped customer record, queue up a welcome email, send a
- 15:18Speaker 2: Slack notification.
- 15:20Speaker 1: Okay, lots of steps right.
- 15:22Speaker 2: Putting all that logic directly in your user's controller would
- 15:24Speaker 2: be a mess. The service object orchestrates it cleanly. You
- 15:28Speaker 2: can even use namespaces like notification services, dot, Slack, webooks,
- 15:32Speaker 2: dot new account to organize related services.
- 15:35Speaker 1: Okay, that makes sense. Now, Some of those steps like
- 15:38Speaker 1: sending emails or talking to stripe might take a second
- 15:40Speaker 1: or two. How do you prevent that from slowing down
- 15:43Speaker 1: the user's request?
- 15:44Speaker 2: Background jobs absolutely essential for a responsive web apps. You
- 15:48Speaker 2: identify tasks that don't need to happen immediately within the
- 15:51Speaker 2: web request cycle, sending emails, processing images, calling slow external APIs,
- 15:55Speaker 2: and you push them onto a background queue so.
- 15:58Speaker 1: The web request finishes quickly and the job runs later exactly.
- 16:02Speaker 2: The user gets a fast response and a separate process
- 16:05Speaker 2: picks up the job from the queue and executes it
- 16:07Speaker 2: in the background. Keeps your app feeling snappy.
- 16:09Speaker 1: How does Rails handle that?
- 16:11Speaker 2: Rails has a built in framework called active job. It
- 16:14Speaker 2: provides a standard way to define your jobs. Then you
- 16:17Speaker 2: choose a back end adapter to actually run the jobs.
- 16:20Speaker 2: Sidekick is probably the most popular for Rails. It uses rttus.
- 16:23Speaker 2: It's very fast and reliable.
- 16:25Speaker 1: Could use schedule jobs too, like send a daily email yep.
- 16:29Speaker 2: You can use extensions like Sidekick, dot cron or similar
- 16:32Speaker 2: tools to schedule jobs to run at specific times or intervals.
- 16:35Speaker 2: Perfect for daily reminders, weekly reports, nightly cleanups, et cetera.
- 16:39Speaker 1: Speaking of emails, how does Rails actually send.
- 16:42Speaker 2: Them through action mailer? It's another built in framework. You
- 16:45Speaker 2: define mailer classes similar to controllers, with methods for each
- 16:49Speaker 2: type of email you want to send. You can create
- 16:51Speaker 2: both HTML and plaintext versions easily.
- 16:54Speaker 1: And you mentioned deliver later for background jobs right.
- 16:57Speaker 2: You can call deliver now to send it immediate lee
- 17:00Speaker 2: usually only for testing or very specific cases, or deliver
- 17:04Speaker 2: later to queue it up via active job. Always use
- 17:06Speaker 2: deliver later for real world emails.
- 17:09Speaker 1: What else do you need for emails and production just
- 17:11Speaker 1: action mailer?
- 17:12Speaker 2: No, you'll need an actual email delivery service like send grid, Postmark,
- 17:15Speaker 2: or mail gun. Your server itself usually isn't configured for
- 17:18Speaker 2: reliable mass email delivery. You also need to configure DNS
- 17:22Speaker 2: records SBF, DKM for your domain to ensure your emails
- 17:26Speaker 2: don't end up in spam folders.
- 17:27Speaker 1: And apikeys for those services, How do you store those? Securely?
- 17:30Speaker 2: Rails credentials It's a built in way to manage secrets.
- 17:34Speaker 2: It creates an encrypted file canfig credentials, dot email, dot
- 17:37Speaker 2: enc where you store apikeys and other sensitive stuff. This
- 17:41Speaker 2: file can be checked in to get but you need
- 17:44Speaker 2: the master key canfig master dot key which you never
- 17:46Speaker 2: check in to decrypt it. Very secure way to handle secrets.
- 17:50Speaker 1: Okay, that's sending email. What about receiving email? Can rails
- 17:53Speaker 1: handle replies? Yes?
- 17:56Speaker 2: This is super powerful. Action Mailbox is the framework for this.
- 18:00Speaker 2: That's your Rails application receive incoming emails. You can figure
- 18:03Speaker 2: specific email addresses like replies at your wapp dot com
- 18:06Speaker 2: to route emails into your application.
- 18:09Speaker 1: What could you do with them?
- 18:09Speaker 2: Then you define mailboxes that process incoming emails. Based on
- 18:13Speaker 2: routing rules, you can parse the email content, extract data,
- 18:16Speaker 2: and trigger actions in your app. Imagine replying to a
- 18:19Speaker 2: stand up reminder email with your updates and action Mailbox
- 18:22Speaker 2: automatically parses it and saves your stand up Very cool stuff.
- 18:25Speaker 1: Wow, Okay, that opens up possibilities. Let's talk money. Stripe
- 18:29Speaker 1: integration for payments and subscriptions. How does that typically work?
- 18:32Speaker 2: In rail SaaS Stripe is pretty much the de facto standard.
- 18:35Speaker 2: It's very developer friendly. First, you define your products and
- 18:39Speaker 2: prices in the Stripe dashboard, your different subscription tiers, free, pro,
- 18:44Speaker 2: enterprise and how much they.
- 18:45Speaker 1: Cost, and link those to your app.
- 18:47Speaker 2: Yeah. You often map those Stripe product price IDs to
- 18:51Speaker 2: something in your application, maybe a configuration file, products dot
- 18:54Speaker 2: AML or a simple product model. This lets your app
- 18:58Speaker 2: know the limits associated with each plan like max users,
- 19:02Speaker 2: features available, etc.
- 19:03Speaker 1: How does the sign up flow work with Stripe?
- 19:05Speaker 2: Typically, when a user signs up or upgrades, your application
- 19:09Speaker 2: interacts with stripes API. You create a Stripe customer object
- 19:13Speaker 2: for the user count. Then you create a subscription linking
- 19:16Speaker 2: that customer to a specific price. Stripe handles the actual
- 19:19Speaker 2: payment processing. Your app just needs to store the Stripe
- 19:22Speaker 2: customer ID and subscription ID on your account or user model,
- 19:25Speaker 2: and then.
- 19:26Speaker 1: You check that subscription status to enforce limits exactly.
- 19:29Speaker 2: You'll have logic, maybe a before reaction in your controllers
- 19:32Speaker 2: or checks within specific features that looks at the account's
- 19:36Speaker 2: subscription status. Is the subscription active, what plan are they on?
- 19:40Speaker 2: Based on that, you allow or deny actions, or maybe
- 19:43Speaker 2: redirect them to a billing page if they hit a limit.
- 19:46Speaker 2: Stripe provides a pre built billing portal you can easily
- 19:49Speaker 2: link users to for managing their subscription.
- 19:52Speaker 1: And testing this. You don't want to actually charge credit
- 19:55Speaker 1: cards during.
- 19:55Speaker 2: Tests, absolutely not. This is where mocking comes in again.
- 19:59Speaker 2: You use libra is like webmoc or VCR again to
- 20:02Speaker 2: intercept any calls to the Stripe API during your tests,
- 20:05Speaker 2: you provide fake successful or failed responses. This ensures your
- 20:09Speaker 2: tests run quickly and reliably without hitting striped servers or
- 20:12Speaker 2: needing real card details. Crucial.
- 20:15Speaker 1: Okay, beyond payments, what about integrating with other APIs like GitHub?
- 20:19Speaker 2: The pattern is often similar, usually involving o off for authorization.
- 20:23Speaker 2: For GitHub, you'd register an oof app. When a user
- 20:26Speaker 2: wants to connect their account, you redirect them to Gethub
- 20:29Speaker 2: to authorize your application.
- 20:30Speaker 1: Big grant permission right.
- 20:32Speaker 2: GitHub redirects them back to your app with a temporary code.
- 20:35Speaker 2: Your app then exchanges that code securely with GitHub's API
- 20:39Speaker 2: to get an access token. You store that token securely,
- 20:43Speaker 2: maybe using Rails credentials or database encryption, and then you
- 20:47Speaker 2: can use it to make API calls on the user's
- 20:49Speaker 2: behalf like listing their repositories.
- 20:51Speaker 1: And getting real time updates from GitHub like new code pushes.
- 20:55Speaker 2: That's webhooks. You'd use the GitHub API using the user's
- 20:59Speaker 2: token to tell GitHub, Hey, whenever there's a push event
- 21:02Speaker 2: on this repo, send a notification to this URL on
- 21:05Speaker 2: my application.
- 21:06Speaker 1: So getthub calls your app exactly.
- 21:08Speaker 2: Your app needs an endpoint ready to receive that webhook data.
- 21:11Speaker 2: You'd probably store these incoming events in your database, maybe
- 21:14Speaker 2: in an event table. STI could be useful here too.
- 21:16Speaker 2: For different types of events push event, pull request event,
- 21:19Speaker 2: you might store the raw event, payload and adjson B
- 21:22Speaker 2: column for flexibility.
- 21:23Speaker 1: And finally, tracking what users are doing in the app.
- 21:26Speaker 2: Analytics Yeah, super important for understanding usage and making decisions.
- 21:30Speaker 2: Tools like mixed Panel or segment or common you integrate
- 21:34Speaker 2: their stks and send events from your rails app back
- 21:37Speaker 2: end or potentially the front end. JavaScript you identify users
- 21:41Speaker 2: and track key actions users sign up, page viewed, feature used,
- 21:46Speaker 2: stand up, created, plan, upgraded gives you valuable insights into
- 21:50Speaker 2: user behavior.
- 21:51Speaker 1: Okay, we've built a lot, now making it fast and
- 21:53Speaker 1: getting it deployed. Optimizations First, what are the low hanging fruit,
- 21:57Speaker 1: the real bang for your buck performance improvements?
- 22:00Speaker 2: Good question? First, know where the slownesses. Tools like Rackmini
- 22:05Speaker 2: Profiler show you database query times and rendering times right
- 22:08Speaker 2: in your browser during development. Essential first step.
- 22:11Speaker 1: Okay, diagnose first, Then what.
- 22:13Speaker 2: N plus one queries? Huge performance killer. This is when
- 22:16Speaker 2: you load a list of things like teams and then
- 22:18Speaker 2: loop through them, making a separate database query inside the
- 22:20Speaker 2: loop to get related data like the users for each team.
- 22:23Speaker 1: One query for the list, then end queries inside.
- 22:26Speaker 2: The loop exactly. You fix it with eager loading. In Rails,
- 22:30Speaker 2: you use dot includes or references on your initial query
- 22:35Speaker 2: team dot includes, dot users, dot all that tells Rails
- 22:38Speaker 2: to fetch all the teams and their associated users in
- 22:41Speaker 2: just one or two efficient queries.
- 22:43Speaker 1: Are there tools to fined N plus ones?
- 22:45Speaker 2: Yes? The bullet gem is fantastic for detecting N plus
- 22:48Speaker 2: one queries and other database issues automatically during development. It'll
- 22:52Speaker 2: pop up warnings telling you where to add eager loading.
- 22:55Speaker 1: What else slows down database access.
- 22:57Speaker 2: Missing database indices. If you're freequently looking up records by
- 23:01Speaker 2: a column that doesn't have an index, like finding a
- 23:03Speaker 2: user by email, the database has to scan the hotal
- 23:07Speaker 2: terribly slow on large tables.
- 23:08Speaker 1: How do you find missing indices?
- 23:10Speaker 2: Tools like luld blog can scan your models and usage
- 23:12Speaker 2: patterns and suggest indices you should add. Adding the right
- 23:15Speaker 2: indices can make lookups orders of magnitude faster.
- 23:18Speaker 1: What about just displaying lots of data like a huge
- 23:21Speaker 1: list of stand ups pagination.
- 23:24Speaker 2: Don't try to load and render thousands of records on
- 23:26Speaker 2: one page. It kills memory and browser performance. Use a
- 23:30Speaker 2: gem like pagy, which is very fast and memory efficient
- 23:34Speaker 2: to break results into pages, show twenty or fifty items
- 23:37Speaker 2: at a time. Huge improvement for user experience and serverload.
- 23:40Speaker 1: Any quick server side wins Gzip compression.
- 23:44Speaker 2: Rails has middleware called rack deflator that can automatically compress
- 23:48Speaker 2: responses htmail json before sending them to the browser. Smaller
- 23:52Speaker 2: response size means faster downloads. It's usually just a one
- 23:55Speaker 2: line configuration change.
- 23:57Speaker 1: Easy win, okay, and the big one casing How does that?
- 24:00Speaker 2: Cashing is probably the single most impactful performance technique. The
- 24:04Speaker 2: basic idea is don't recalculate or rerender something if it
- 24:07Speaker 2: hasn't changed, store the result and reuse it.
- 24:10Speaker 1: Where do you store the cash stuff?
- 24:11Speaker 2: You can figure a cash store. Rettis is very common
- 24:14Speaker 2: and versatile for cashing in Rails. Memcash is another option.
- 24:18Speaker 2: You can even use the filesystem or memory for development.
- 24:21Speaker 1: What kinds of things can you cash?
- 24:22Speaker 2: Several levels. There's low level caching, where you cash raw
- 24:26Speaker 2: data like the result of a complex query. Then there's
- 24:29Speaker 2: fragment caching, which is really powerful in RAILS views. You
- 24:32Speaker 2: wrap a piece of HTML, maybe a complex partial in
- 24:35Speaker 2: a cash block. Rails renders at once, stores the HPML fragment,
- 24:39Speaker 2: and reuses it on subsequent requests until the underlying data changes.
- 24:43Speaker 1: How does it know when the data changes?
- 24:45Speaker 2: Typically through cash keys based on the objects being rendered.
- 24:49Speaker 2: If you cash a block based on a at product object,
- 24:52Speaker 2: Rails uses the products it and update at timestamp and
- 24:55Speaker 2: the key. When the product updates, the key changes and
- 24:59Speaker 2: the cash is invalid.
- 25:00Speaker 1: In Russian doll caching sounds complex.
- 25:03Speaker 2: It builds on fragment caching. Imagine you cash a list
- 25:05Speaker 2: of products, and each product in the list is also
- 25:08Speaker 2: cashed individually, like nested Russian dolls. The magic is that
- 25:12Speaker 2: if you update one product, Rails can automatically invalidate just
- 25:16Speaker 2: that product's fragment and the outerless cash that contained it.
- 25:19Speaker 2: It often involves using touch true on model associations or
- 25:22Speaker 2: after commit hooks to ensure parent objects updated timestamps change
- 25:26Speaker 2: when children change, automatically busting the cash. Very efficient. How
- 25:30Speaker 2: you set up cashing, You can figure your cash store
- 25:32Speaker 2: in your environment files example fund environments, production, dot RP
- 25:36Speaker 2: tell Rails to use reddis You can easily toggle cashing
- 25:38Speaker 2: on off and development with binrailsdev dot cash.
- 25:41Speaker 1: Okay apps optimized time to deploy. Heroku is mentioned as popular.
- 25:46Speaker 1: How do you prep for that?
- 25:47Speaker 2: Heroku is great for getting started. Before deploying. You need
- 25:50Speaker 2: to configure production specific settings your domain name, mailer settings
- 25:55Speaker 2: using those SND grid keys, maybe forcing SSL.
- 25:57Speaker 1: And the deployment process itself.
- 25:59Speaker 2: It's pretty standard Heroku workflow. Install the Heroku Cli two belt,
- 26:04Speaker 2: run Heroku create to create your app. Add necessary add
- 26:07Speaker 2: ons like postgrass, Heroku add ons dot create, Heroku postgress
- 26:10Speaker 2: call and rettis Heroku add ons dot create, Heroku rettis.
- 26:14Speaker 2: Set your environment variables securely using Heroku configu do set,
- 26:17Speaker 2: especially the Rails master key needed to decrypt your credentials.
- 26:21Speaker 2: You might need to adjust your profile to specify how
- 26:23Speaker 2: many web workers and background job sidecack workers to run.
- 26:26Speaker 2: Then it's just get push Heroku Maine to deploy your code,
- 26:29Speaker 2: followed by Heroku run rails dB dot migrate to update
- 26:32Speaker 2: the production database.
- 26:33Speaker 1: STEMA seems straightforward enough for basic deployment. Any other cool
- 26:37Speaker 1: modern rails tools worth mentioning for sauce.
- 26:39Speaker 2: Oh yeah, Rail seven brought lotuing for active record queries.
- 26:44Speaker 2: If you have a page that needs to run say
- 26:46Speaker 2: three independent database queries to gather data for different sections
- 26:50Speaker 2: look at dashboard exactly. Instead of running them one after another,
- 26:53Speaker 2: lotusink lets them run concurrently, potentially speeding up data loading significantly.
- 26:59Speaker 2: And another big one is active record encryption.
- 27:02Speaker 1: Encrypting data in the database YEP.
- 27:04Speaker 2: Rail seven has built in support using the encrypts declaration
- 27:07Speaker 2: in your model. You can mark attributes like user dotcrypts
- 27:10Speaker 2: dot email or task dotcrypts dot title. Rails handles the
- 27:15Speaker 2: encryption and decryption automatically and transparently for your application. The
- 27:19Speaker 2: data is stored encrypted at rest in the database, but
- 27:21Speaker 2: your app code just reads and writes it normally. Adds
- 27:24Speaker 2: a great layer of security for sensitive data.
- 27:26Speaker 1: Wow, that's built right in. Very nice. Okay, so we've
- 27:29Speaker 1: covered a kind of ground here. What does this all
- 27:31Speaker 1: mean for someone listening trying to learn or build their
- 27:34Speaker 1: own saws.
- 27:35Speaker 2: I think the big takeaway is seeing the whole journey
- 27:37Speaker 2: mapped out from that initial Rails new and setting up
- 27:40Speaker 2: users with solid off through building core features, handling payments,
- 27:45Speaker 2: integrating APIs, using background jobs all the way to optimizing
- 27:49Speaker 2: and deploying. Rails provides tools and conventions for almost every step.
- 27:53Speaker 2: It's amazing how this one framework guides you through such complexity,
- 27:57Speaker 2: often quite elegantly.
- 27:59Speaker 1: It really paints picture of how all these pieces connect.
- 28:02Speaker 1: The database, the back end logic, the frontend reactivity with
- 28:05Speaker 1: hot wire, the external services.
- 28:08Speaker 2: Absolutely, building a sauce is a deep dive. It's not
- 28:10Speaker 2: just one thing, it's this whole ecosystem of interconnected parts
- 28:13Speaker 2: working together.
- 28:14Speaker 1: So as you, the listener, reflect on everything we've unpacked
- 28:17Speaker 1: from this guide, here's something to think about. How might
- 28:20Speaker 1: understanding this deep interplay between that server driven frontend reactivity
- 28:25Speaker 1: like hot wire and the back end efficiency techniques like
- 28:27Speaker 1: background jobs and sophisticated caching. How might that fundamentally change
- 28:32Speaker 1: the way you approach building your next major software project,
- 28:35Speaker 1: even if you're not using rails