📄 Page
1
(This page has no text content)
📄 Page
2
ß Under Construction: The book you’re reading is still under development. As part of our Beta book program, we’re releasing this copy well before a normal book would be released. That way you’re able to get this content a couple of months before it’s available in finished form, and we’ll get feedback to make the book even better. The idea is that everyone wins! Be warned: The book has not had a full technical edit, so it will contain errors. It has not been copyedited, so it will be full of typos, spelling mistakes, and the occasional creative piece of grammar. And there’s been no effort spent doing layout, so you’ll find bad page breaks, over-long code lines, incorrect hyphen- ation, and all the other ugly things that you wouldn’t expect to see in a finished book. It also doesn't have an index. We can’t be held liable if you use this book to try to create a spiffy application and you somehow end up with a strangely shaped farm implement instead. Despite all this, we think you’ll enjoy it! Download Updates: Throughout this process you’ll be able to get updated ebooks from your account at pragprog.com/my_account. When the book is com- plete, you’ll get the final version (and subsequent updates) from the same ad- dress. Send us your feedback: In the meantime, we’d appreciate you sending us your feedback on this book at pragprog.com/titles/dcbang2/errata, or by using the links at the bottom of each page. Thank you for being part of the Pragmatic community! Andy
📄 Page
3
Rails, Angular, Postgres, and Bootstrap, Second Edition David Bryant Copeland The Pragmatic Bookshelf Raleigh, North Carolina
📄 Page
4
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade- marks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic books, screencasts, and audio books can help you and your team create better software and have more fun. Visit us at https://pragprog.com. For sales, volume licensing, and support, please contact support@pragprog.com. For international rights, please contact rights@pragprog.com. Copyright © 2016 The Pragmatic Programmers, LLC. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. ISBN-13: 978-1-68050-220-6 Encoded using the finest acid-free high-entropy binary digits. Book version: B1.0—October 19, 2016
📄 Page
5
Contents Introduction . . . . . . . . . . . . . v 1. Set Up the Environment . . . . . . . . . . 1 Installing Ruby, Rails, and Postgres 1 Creating the Rails Application 2 Setting Up Bootstrap with NPM and Webpack 6 Next: Authentication with Devise, Styled by Bootstrap 16 2. Create a Great-Looking Login with Bootstrap and Devise . . 17 Adding Authentication with Devise 17 Styling the Login and Registration Forms 22 Validating Registration 28 Next: Using Postgres to Make Our Login More Secure 29 3. Secure the User Database with Postgres Constraints . . . 31 Exposing the Vulnerability Devise and Rails Leave Open 31 Preventing Bad Data Using Check Constraints 32 Why Use Rails Validations? 37 Next: Using Postgres Indexes to Speed Up a Fuzzy Search 38 4. Perform Fast Queries with Advanced Postgres Indexes . . 39 Implementing a Basic Fuzzy Search with Rails 40 Understanding Query Performance with the Query Plan 51 Indexing Derived and Partial Values 53 Next: Better-Looking Results with Bootstrap’s List Group 56 5. Create Clean Search Results with Bootstrap Components . 57 Creating Google-Style Search Results Without Tables 58 Paginating the Results Using Bootstrap’s Components 63 Next: Angular! 67
📄 Page
6
6. Build a Dynamic UI with AngularJS . . . . . . . 69 Configuring Rails and Angular 70 Porting Our Search to Angular 76 Changing Our Search to Use Typeahead 91 Next: Testing 94 7. Test This Fancy New Code . . . . . . . . . 95 Installing RSpec for Testing 96 Testing Database Constraints 99 Running Headless Acceptance Tests in PhantomJS 103 Writing Unit Tests for Angular Components 117 Next: Level Up on Everything 128 8. Create a Single-Page App Using Angular’s Router . . . 131 Storing View Templates in HTML Files 133 Configuring Angular’s Router for User Navigation 136 Navigating the User Interface Client-side 144 Implementing Back-End Integration Using TDD 148 Next: Design Using Grids 158 9. Design Great UIs with Bootstrap’s Grid and Components . 159 The Grid: The Cornerstone of a Web Design 160 Using Bootstrap’s Grid 162 Adding Polish with Bootstrap Components 168 Next: Populating the View Easily and Efficiently 172 10. Cache Complex Queries Using Materialized Views . . . 175 Understanding the Performance Impact of Complex Data 176 Using Materialized Views for Better Performance 185 Keeping Materialized Views Updated 190 Next: Combining Data with a Second Source in Angular 196 11. Asynchronously Load Data from Many Sources . . . . 197 12. Wrangle Forms and Validations with Angular . . . . 199 13. Dig Deeper . . . . . . . . . . . . . 201 A1. Full Listing of Customer Detail Page HTML . . . . . 203 A2. Creating Customer Address Seed Data . . . . . . 205 A3. How Webpack Affects Deployment . . . . . . . 207 Bibliography . . . . . . . . . . . . 209 Contents • iv
📄 Page
7
Introduction Think about what part of an application you’re most comfortable working with. If you’re a Rails developer, there’s a good chance you prefer the back end, the Ruby code that powers the business logic of your application. What if you felt equally comfortable working with the database, such as tweaking queries and using advanced features of your database system? What if you were also comfortable working with the JavaScript and CSS necessary to make dynamic, usable, attractive user interfaces? If you had that level of comfort at every level of the application stack, you would possess great power as a developer to quickly produce high-quality software. Your ability to solve problems would not be restricted by the tools available via a single framework, nor would you be at the mercy of hard-to- find specialists to help you with what are, in reality, simple engineering tasks. The Rails framework encourages developers not to peer too closely into the database. Rails steers you away from JavaScript frameworks in favor of its sprinkling approach, where content is all rendered server-side. This book is going to open your eyes to all the things you can accomplish with your database, and set you on a path that includes JavaScript frameworks. With Rails acting as the foundation of what you do, you learn how to embrace all other parts of the application stack. The Application Stack User Interface Middleware Data Store Many web applications—especially those built with Ruby on Rails—use a layered architec- ture that is often referred to as a stack, since most diagrams (like the ones used in this book) depict the layers as stacked blocks. Rails represents the middle of the stack and is called middleware. This is where the core logic of your application lives. The bottom of the stack—the data store—is where the valuable data saved report erratum • discuss
📄 Page
8
and manipulated by your application lives. This is often a relational database management system (RDBMS). The top of the stack is the user interface. In a web application, this is HTML, CSS, and JavaScript served to a browser. Each part of the stack plays a crucial role in making software valuable. The data store is the canonical location of the organization’s most important asset —its data. Even if the organization loses all of its source code, as long as it retains its data, it can still survive. Losing all of the data, however, would be catastrophic. The top of the stack is also important, as it’s the way the users view and enter data. To the users, the user interface is the database. The difference between a great user interface and a poor one can mean the difference between happy users and irritated users, accurate data and unreliable data, a successful product and a dismal failure. What’s left is the part of the stack where most developers feel most comfort- able: the middleware. Poorly constructed middleware is hard to change, meaning the cost of change is high, and thus the ability of the organization to respond to changes is more difficult. Each part of the stack plays an important role in making a piece of software successful. As a Rails developer, you have amassed many techniques for making the middleware as high quality as you can. Rails (and Ruby) makes it easy to write clean, maintainable code. Digging deeper into the other two parts of the stack will have a great benefit for you as a developer. You’ll have more tools in your toolbox, making you more effective. You’ll also have a much easier time working with specialists, when you do have access to them, since you’ll have a good grasp of both the database and the front end. That’s what you learn in this book. When you’re done, you’ll have a holistic view of application development, and you’ll have a new and powerful set of tools to augment your knowledge of Rails. With this holistic view, you can build seemingly complex features easily, sometimes even trivially. You’ll learn PostgreSQL, AngularJS, and Bootstrap, but you can apply many of the lessons here to other data stores, JavaScript libraries, and CSS frameworks. In addition to seeing just how powerful these specific tools can be, you’re going to be emboldened to think about writing software beyond what is provided by Rails. Introduction • vi report erratum • discuss
📄 Page
9
PostgreSQL, Angular, and Bootstrap: The Missing Parts of Our Stack If all you’ve done with your database is create tables, insert data, and query it, you’re going to be excited when you see what else you can do. Similarly, if all you’ve done with your web views is sprinkle some jQuery calls to your server-rendered HTML, you’ll be amazed at what you can do with very little code when you have a full-fledged JavaScript framework. Lastly, if you’ve been hand-rolling your own CSS, a framework like Bootstrap will make your life so much simpler, and your views will look and feel so much better. In this book, we focus on PostgreSQL (or simply Postgres) as our data store —the bottom of the stack—and AngularJS (or just Angular) with Bootstrap as our front end—the top of the stack. Each of these technologies is widely used and very powerful. You’re likely to encounter them in the real world, and they each underscore the sorts of features you can use to deliver great software outside of what you get with Rails. With these chosen technologies, our application stack looks like this: Angular Bootstrap Rails Postgres In each chapter, I highlight the parts of the stack you’ll be focusing on and call out the various aspects of these technologies you’ll be learning. Not every chapter focuses on all parts of the stack, so at the start of each chapter, you’ll see a roadmap like this of what you’ll be learning: Angular Bootstrap Rails Postgres Focus of this chapter Focus of this chapter Not part of this chapter LOGIN Feature we're working on Form Styles Devise Aspects of the technologies we'll see in this chapter Let’s get a taste of what each has to offer, starting with PostgreSQL. report erratum • discuss The Application Stack • vii
📄 Page
10
PostgreSQL PostgreSQL1 is an open source SQL database released in 1997. It supports many advanced features not found in other popular open source databases such as MySQL2 or commercial databases such as Microsoft SQL Server.3 Here are some of the features you’ll learn about (and I’ll show you how to use them with Rails): Check constraints You can create highly complex constraints on your table columns beyond what you get with not null. For example, you can require that a user’s email address be on a certain domain, that the state in a U.S. address be written exactly as two uppercase characters, or even that the state in the address must already be on a list of allowed state codes. While you can do this with Rails, doing it in the database layer means that no bug in your code, no existing script, no developer at a console, and no future program can put bad data into your database. This sort of data integrity just isn’t possible with Rails alone. Advanced indexing In many database systems, you can only index the values in the columns of the database. In Postgres, you can index the transformed values. For example, you can index the lowercased version of someone’s name so that a case-insensitive search is just as fast as an exact-match search. Materialized views A database view is a logical table based on a SELECT statement. In Postgres a materialized view is a view whose contents are stored in an actual table —accessing a materialized view won’t run the query again like it would in a normal view. Advanced data types Postgres has support for enumerated types, arrays, and dictionaries (called HSTOREs). In most database systems, you have to use separate tables to model these data structures. Free-form JSON…that’s indexed Postgres supports a JSON data type, allowing you to store arbitrary data in a column. This means you can use Postgres as a document data store, or for storing data that doesn’t conform to a strong schema (something 1. https://www.postgresql.org 2. https://www.mysql.com 3. http://www.microsoft.com/en-us/server-cloud/products/sql-server Introduction • viii report erratum • discuss
📄 Page
11
you’d otherwise have to use a different type of database for). And, by using the JSONB data type, you ensure that the JSON fields can be indexed, just like a structured table’s fields. Although you can serialize hashes to JSON in Rails using the TEXT data type, you can’t query them, and you certainly can’t index them. JSONB fields can interoperate with many systems other than Rails, and they provide great performance. AngularJS AngularJS4 is a JavaScript framework created and maintained by Google. Angular allows you to model your user interface as components, which combine a model, template, and code all into one self-contained class. This means your view is not a static bit of HTML, but a full-blown application. By adopting the mind-set that your front end is a dynamic, connected interface comprised of components, and not a set of static pages, you open up many new possibil- ities. Angular provides powerful tools for organizing your code and lets you structure your markup to create intention-revealing, testable, manageable front-end code. It doesn’t matter how small or large the task—as your UI gets more complex, Angular scales much better than something more basic like jQuery. As an example, consider showing and hiding a section of the DOM using jQuery. You might do something like this: jquery_example.html <section> <p>You currently owe: $123.45</p> <button class="reveal-button">Show Details</button> <ul style="display: none" class="details"> <li>Base fee: $120.00</li> <li>Taxes: $3.45</li> </ul> </section> <script> $(".reveal-button").click(function($event) { $(".details").toggle(); }); </script> It’s not much code, but if you’ve ever done anything moderately complex, your markup and JavaScript becomes a soup of magic strings, classes starting with js-, and oddball data- elements. 4. https://angular.io report erratum • discuss The Application Stack • ix
📄 Page
12
An Angular version of this might look like this: var DetailsComponent = ng.core.Component({ template: '\ <section> \ <p>You currently owe: $123.45</p> \ <button on-click="toggleDetails()">Show/Hide Details</button> \ <ul *ngIf="showDetails"> \ <li>Base fee: $120.00</li> \ <li>Taxes: $3.45</li> \ </ul> \ </section> \ ' }).Class({ constructor: function() { this.showDetails = false; }, toggleDetails: function() { this.showDetails = !this.showDetails; } }); It may seem oddly-shaped, but it should reveal its intent much more clearly than the jQuery version, despite the extra bits of code. Without knowing Angular at all, you can piece together that when the button is clicked, it calls the toggleDetails button, and if showDetails is true, we’ll show the detailed informa- tion inside the ul. This all maps closely to the user’s actions and intent. There’s nothing in this code about locating DOM elements or handling browser events. And, when you need to do fancier or more complex interactions in your front end, writing code this way is still easy to manage. Unlike Postgres—where there are very few comparable open source alternatives that match its features and power—there are many JavaScript frameworks comparable to Angular. Many of them are quite capable of handling the fea- tures covered in this book. We’re using Angular for a few reasons. First, it’s quite popular, which means you can find far more resources online for learning it, including deep dives beyond what is covered here. Second, it allows you to compose your front end similarly to how you compose your back end in Rails, but it’s flexible enough to allow you to deviate later if you need to. If you’ve never done much with JavaScript on the front end, or if you’re just used to jQuery, you’ll be pleasantly surprised at what Angular gives you: Introduction • x report erratum • discuss
📄 Page
13
Clean separation of code and views Angular models your front end as an application with its own routes, controllers, and views. This makes organizing your JavaScript easy and tames a lot of complexity. Unit testing from the start Testing JavaScript—especially when it uses jQuery—has always been a challenge. Angular was designed from the start to make unit testing your JavaScript simple and convenient. Clean, declarative views Angular views are just HTML. Angular adds special attributes called directives that allow you to cleanly connect your data and functions to the markup. You won’t have inline code or scripts, and a clear separation exists between view and code. Huge ecosystem Because of its popularity, there’s a large ecosystem of components and modules. Many common problems have a solution in Angular’s ecosystem. It’s hard to fully appreciate the power of a JavaScript framework like Angular without using it, but we’ll get there. We’ll turn a run-of-the-mill search feature into a dynamic, asynchronous live search, with very little code. Bootstrap Bootstrap5 is a CSS framework created by Twitter for use in their internal applications. A CSS framework is a set of CSS classes you apply to markup to get a particular look and feel. Bootstrap also includes design components, which are classes that, when used on particular HTML elements in particular ways, produce a distinct visual artifact, like a form, a panel, or an alert mes- sage. The advantage of a CSS framework like Bootstrap is that you can create full- featured user interfaces without writing any CSS. Why be stuck with an ugly and hard-to-use form like this? 5. http://getbootstrap.com report erratum • discuss The Application Stack • xi
📄 Page
14
By just adding a few classes to some elements, you can have something pol- ished and professional like this instead: Bootstrap includes a lot of CSS for a lot of different occasions: Typography Just including Bootstrap in your application and using semantic HTML results in pleasing content with good general typography. Grid Bootstrap’s grid makes it easy to lay out complex, multicolumn compo- nents. It can’t be overstated how important and powerful this is. Form styles Styling good-looking forms can be difficult, but Bootstrap provides many CSS classes that make it easy. Bootstrap-styled forms have great spacing and visual appeal, and feel cohesive and inviting to users. Components Bootstrap also includes myriad components, which, as mentioned earlier, are CSS classes that, when applied to particular markup, generate a visual component like a styled box or alert message. These components can be great inspiration for solving simple design problems. It’s important to note that Bootstrap is not a replacement for a designer, nor are all UIs created with Bootstrap inherently usable. There are times when a specialist in visual design, interaction design, or front-end implementation is crucial to the success of a project. But for many apps, you don’t need these specialists (they are very hard to find when you do). Bootstrap lets you produce a professional, appealing user interface without them. Bootstrap also lets you realize visual designs that might seem difficult to do with CSS. Even if you have a designer or front-end specialist, the skills you’ll learn by using Bootstrap will still apply—your front-end developer isn’t going to write Introduction • xii report erratum • discuss
📄 Page
15
every line of markup and CSS. They are going to hand you a framework like Bootstrap that enables you to do many of the things we’ll do in this book. Now that you’ve gotten a taste of what we’ll be covering, let’s talk about how you’re going to learn it. How to Read This Book If you’ve already looked at the table of contents, you’ll see that this book isn’t divided into three parts—one for Postgres, one for Angular, and one for Bootstrap. That’s not how a full-stack developer approaches development. A full-stack developer is given a problem to solve and is expected to bring all forces to bear in solving it. For example, if you’re implementing a search, and it’s slow, you’ll probably consider both creating an index in the database as well as performing the search with Ajax calls to create a more dynamic and snappy UI. You should use features at every level of the stack to get the job done, as shown in the following diagram. SEARCH FEATURE Angular Bootstrap Rails Postgres Search Form Search Logic Ajax Calls Results View Indexes This holistic approach is how you’re going to learn these technologies, and you’ll have the most success reading the book in order. We’ll build a Rails application together, adding features one at a time. These features will demonstrate various aspects of the technologies you’re using. Shine, the Application We Build Throughout the chapters in this book we’ll create and add features to a Rails application. We’re creating this application for the customer service agents at the hypothetical company where we work. Our company has a public website that its customers use, but we want a separate application for the report erratum • discuss How to Read This Book • xiii
📄 Page
16
customer service agents. You’ve probably seen or heard about internal-facing apps like this. Perhaps you’ve even worked on one (most software is internally facing). The application will be called Shine (since it allows our great customer service to shine through to our customers). The features that we’ll build for this application involve searching for, viewing, and manipulating customer data. For example, we’ll allow the user to search for customers in a manner similar to what is shown in the following figures. They’ll also be allowed to click through and view or edit a customer’s data. Googlehttp://shine.example.com/customers/1234 Shine: Customer 1234 Pat Pat Jones pj1234 pjones18@somewhere.net JOINED 10/12/2014 Darrell Patrick dpat darrel@somewhere.net JOINED 1/13/2014 Patty Smith ppsmith smith.p@somewhere.net JOINED 10/12/2014 Introduction • xiv report erratum • discuss
📄 Page
17
Googlehttp://shine.example.com/customers/1234 Shine: Customer 1234 Customer Info Billing Info Shipping Address Pat Jones pat1234@ pj@somewhere.net JOINED 2/13/2014 123 Any St Unit 101 Washington 20002DC 123 Any St Unit 101 Washington 20002DC View at Payment Processor… Same as Shipping?Billing Address ****-****-****-1234 Expires 12/18VISA Hide if “Same as Shipping” checked These features may seem simple on the surface, but there’s hidden complex- ity that you’ll be able to tame with Postgres, Angular, and Bootstrap. In each chapter, you’ll make a bit of progress on Shine, and you’ll learn features of Postgres, Angular, Bootstrap, and Rails in the process. How We’ll Build Shine To keep things simple, each chapter focuses on a single technology, and you complete features over several chapters. We’ll do as much setup as we can in Chapter 1, Set Up the Environment, on page 1. Because our goal is to bring together several technologies that weren’t designed as a single package, we’ll have to do a bit more configuration up front, but once that configuration is done, we’ll be ready to add features and get the most out of everything. The first feature we build is a registration and login system, which allows us to style the user interface with Bootstrap as well as secure the underlying database with Postgres. We get our Rails application set up and style the login in Chapter 2, Create a Great-Looking Login with Bootstrap and Devise, on page 17. We then tighten up the security by learning about check con- straints in Chapter 3, Secure the User Database, on page 31. report erratum • discuss How to Read This Book • xv
📄 Page
18
We then move on to a customer search feature, which is a fertile ground for learning about full-stack development. In Chapter 4, Perform Fast Queries with, on page 39, we implement a basic fuzzy search, and you learn how to examine Postgres’s query plan to understand why our search is slow. We then use Postgres’s advanced indexing features to make it fast. In Chapter 5, Create Clean Search Results, on page 57, you learn how to use some of Bootstrap’s built-in components and helper classes to create nontabular search results that look great. Chapter 6, Build a Dynamic UI with AngularJS, on page 69, is an introduction to AngularJS, which we use to make our customer search much more dynamic. This chapter explores how to set up and manage Angular as part of the asset pipeline, as well as how to read user input and do Ajax calls to our Rails application. With a fully implemented customer search, we pause in Chapter 7, Test This Fancy New Code, on page 95 to discuss how to write tests for everything you’ve learned. Testing has always been a big part of Rails, so whenever we veer off Rails’s golden path, it’s important to make sure we have a great testing experience. Chapter 8, Create a Single-Page App, on page 131 is our first step in building a more complex feature that shows customer details. We turn our customer search into a client-side, single-page application that allows the user to nav- igate from search results to customer details without reloading the page. This gives you an opportunity to learn about Angular’s router and navigation fea- tures. In Chapter 9, Design Great UIs with, on page 159, you learn about a powerful web design tool called the grid and how Bootstrap implements it. We use it to create a dense UI that’s clean, clear, and usable. In Chapter 10, Cache Complex Queries, on page 175, we implement the back end of our customer details view by turning a query of highly complex joins into a simple auto- updated cache using Postgres’s materialized views. In Chapter 11, Asynchronously Load Data, on page 197, you learn how Angular’s asynchronous nature allows us to keep our front end simple, even when we need data from several sources. We finish off our customer detail page feature, as well as our in-depth look at these technologies, in Chapter 12, Wrangle Forms and, on page 199, by exploring Angular’s data binding, which allows you to auto-save changes the user makes on the front end. Introduction • xvi report erratum • discuss
📄 Page
19
All of this is just a small part of what you can do with Bootstrap, Angular, and Postgres, so in Chapter 13, Dig Deeper, on page 201, we’ll survey some of the other features we don’t have space to get to. To help you keep track of where we are, each chapter starts with a diagram (like the one shown on page vii) that shows which parts of the stack we are focusing on, what feature we’re building, and what aspects of each technology you are learning in that chapter. When it’s all said and done, you’ll have the confidence needed to solve prob- lems by using every tool available in the application stack. You’ll be just as comfortable creating an animated progress bar as you will be setting up views and triggers in the database. Moreover, you’ll see how you can use these sorts of features from the comfort of Rails. Example Code The running examples in the book are extracted from fully tested source code that should work as shown, but you should download the sample code from the book’s website at https://pragprog.com/titles/dcbang2/source_code. Each step of our journey through this topic has a different subdirectory, each containing an entire Rails application. While the book shows you only the changes you need to make, the downloadable code records a snapshot of the fully working application as of that point in the book. Command-Line Execution We’ll be running a lot of commands in this book. Rails development is heavily command-line driven, and this book shows the commands you need to execute as we go. It’s important to understand how to interpret the way we’re using them in the book. Each time you see a command-line session, the text will first show how you call the command line, followed by the expected output. In the following example, we invoke the command line bundle exec rails generate devise:install. This is the command you’d type into your terminal and press Return. The lines following the command line display expected or example output. $ bundle exec rails generate devise:install create config/initializers/devise.rb create config/locales/devise.en.yml Sometimes I need to show a command-line invocation that won’t fit on one line. In this case, I use backslashes to show the continuation of the command (which is how you’d actually run a multiline command in a shell like bash). report erratum • discuss How to Read This Book • xvii
📄 Page
20
The last line won’t have a backslash. For example, here we’re typing everything from rails to shine. $ rails new --skip-turbolinks \ --skip-spring \ --skip-test-unit \ -d postgresql \ shine create create README.rdoc create Rakefile create config.ru create .gitignore create Gemfile The sample output won’t always match exactly what you see, but it should be close. It’s included so you have a way to sanity-check what you’re doing as you follow along. A second form of command-line session is when we interact with Postgres. I’ll indicate this by executing rails dbconsole first and then showing SQL com- mands inside the Postgres command-line interpreter. In the following listing I’m executing rails dbconsole; then I’m executing select count(*) from users; inside Postgres (note how the prompt changes slightly). After that you see the expected or sample results of the command. $ rails dbconsole postgres> select count(*) from users; | count | +-------+ | 100 | +-------+ What You Need to Know This book covers a lot of advanced topics in web development. However, my hope is that you can get a lot out of it regardless of your skill level. Neverthe- less, the code and concepts are written assuming some basic exposure to the topics at hand: Ruby and Rails Much of the Rails content in the book is in configuration, specifically to get Rails to work with Angular, Bootstrap, and the ecosystem in which they live. If you’ve created a simple Rails app, and you know what con- trollers, models, views, migrations, and tests are, you should have no problem understanding the Rails code. If you’re new to Rails, check out Agile Web Development with Rails 4 [Rub13]. Introduction • xviii report erratum • discuss