Rails Angular Postgres and Bootstrap Powerful Effective and Efficient Full Stack Web Development 1st Edition David Bryant Copeland pdf download
Rails Angular Postgres and Bootstrap Powerful Effective and Efficient Full Stack Web Development 1st Edition David Bryant Copeland pdf download
https://ebookfinal.com/download/web-development-with-bootstrap-4-and-
angular-2-2nd-edition-sergey-akopkokhyants/
https://ebookfinal.com/download/agile-web-development-with-
rails-7-2nd-edition-sam-ruby/
https://ebookfinal.com/download/agile-web-development-with-rails-a-
pragmatic-guide-1st-edition-dave-thomas/
Agile Web Development with Rails 4 4th Revised edition
Edition Sam Ruby
https://ebookfinal.com/download/agile-web-development-with-
rails-4-4th-revised-edition-edition-sam-ruby/
https://ebookfinal.com/download/web-services-on-rails-1st-edition-
kevin-marshall/
https://ebookfinal.com/download/node-js-web-development-3rd-revised-
edition-david-herron/
Rails Angular Postgres and Bootstrap Powerful Effective
and Efficient Full Stack Web Development 1st Edition
David Bryant Copeland Digital Instant Download
Author(s): David Bryant Copeland
ISBN(s): 9781680501261, 1680501267
Edition: 1
File Details: PDF, 8.68 MB
Year: 2016
Language: english
www.it-ebooks.info
www.it-ebooks.info
Early praise for Rails, Angular, Postgres, and Bootstrap
This book is a fantastic resource for anyone looking to gain a practical understand-
ing of full-stack development using contemporary, ubiquitous technologies. I was
particularly impressed by how well the author was able to cover so many different
software components in such a constructive and cohesive manner. As an engineer
who spends most of my time at the data layer, I walked away with a ton of helpful
insight into the other layers of the typical application stack.
➤ Matthew Oldham
Director of data architecture, Graphium Health
A book that deals with integrating Angular into Rails is something I’ve been
waiting a long time for, and what’s here is a definite step above existing online
tutorials. Like the author, I’m used to viewing different database management
systems as black boxes that are much like each other, and this book made me
reconsider that line of thinking. I highly recommend this book for Rails developers
who want to try Angular and make use of PostgreSQL’s advanced features.
➤ Nigel Lowry
Company director, Lemmata
Rails, Angular, Postgres, and Bootstrap is a powerful resource for all software en-
gineers interested in full-stack development. No matter your proficiency at each
level in the stack, you’ll acquire a new technique that’s immediately applicable to
your project.
➤ Simeon Willbanks
Lead software engineer, Stitch Fix
www.it-ebooks.info
This book provides beginner developers with solid steps to get “your” application
running and to be able to see/do it yourself. I recommend the book to Rails devel-
opers beginning their learning journey with Angular.
➤ Maricris Nonato
Senior Ruby on Rails developer, Premiere Speakers Bureau
www.it-ebooks.info
Rails, Angular,
Postgres, and Bootstrap
Powerful, Effective, and Efficient
Full-Stack Web Development
www.it-ebooks.info
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 courses, workshops, and other products can help you and your team create
better software and have more fun. For more information, as well as the latest Pragmatic
titles, please visit us at https://pragprog.com.
www.it-ebooks.info
Contents
Acknowledgments . . . . . . . . . . . ix
Introduction . . . . . . . . . . . . . xi
www.it-ebooks.info
Contents • vi
www.it-ebooks.info
Contents • vii
Bibliography . . . . . . . . . . . . 257
Index . . . . . . . . . . . . . . 259
www.it-ebooks.info
Acknowledgments
I’d like to first thank my wife Amy, who gave me the encouragement and space
to spend time every morning writing this book.
I’d also like to thank my editor, Fahmida Rashid, who managed to take what
started as a functional requirements document for a customer service appli-
cation and helped me turn it into a useful book.
I’d further like to thank the many people who reviewed the in-progress book,
including Chris Hoffman, David McClain, J. Daniel Ashton, Jacob Chae, John
Cater, Maricris Nonato, Matthew Oldham, Nell Shamrell, Nigel Lowry, Simeon
Willbanks, and Jeremy Frens (who had particular insights that I hope I’ve
reflected well). And a huge thanks to the various readers who pointed out
errors in the beta version of the book (including some rather embarrassing
omissions): Andrea Bufalo Riva, Bradford Baker, Brent Nordquist, C. R. Myers,
Chris McCann, Harri Jauri, J. Daniel Ashton, Jamie Finlay, Jesus Alc, John
Lyons, Michael Pope, Narongsak Jirajaruwong, Nick Clyde, Patrick Joyce,
Russ Martin, Sernin van de Krol, Stephen Lloyd, and Volker Wiegand.
Finally, I’d like to thank the contributors to the software you’re learning about
in this book. The people who have given their free time to make Ruby, Rails,
Postgres, Angular, Bootstrap, PhantomJS, Teaspoon, Poltergeist, Devise,
Capybara, RSpec, Angular-UI, Database Cleaner, Bower, and all other open
source software are far too numerous to list here, but without their work,
most developers would have a hard time doing their jobs.
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’ll learn how to embrace
all other parts of the application stack.
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’ll 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.
In this book, we’re going to 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, we’ll highlight the parts of the stack we’ll be focusing on and
call out the various aspects of these technologies you’ll be learning. Not every
chapter will focus 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:
Feature we're
working on
Not part of Focus of
this chapter this chapter
LOGIN
Focus of Form
this chapter Angular Bootstrap Styles Aspects of
the technologies
Devise we'll see in
Rails this chapter
Postgres
Let’s get a taste of what each has to offer, starting with PostgreSQL.
PostgreSQL
PostgreSQL is an open source SQL database released in 1997. It supports
many advanced features not found in other popular open source databases
such as MySQL1 or commercial databases such as Microsoft SQL Server.2
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 (which we’ll see in Chapter 2, Secure the
Login Database, on page 25), 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. We’ll
see this in Chapter 3, Use Fast Queries with, on page 33.
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. We’ll use one in Chapter 9, Cache Complex
Queries, on page 151.
1. https://www.mysql.com/
2. http://www.microsoft.com/en-us/server-cloud/products/sql-server/
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
AngularJS3 is a JavaScript Model-View-Controller (MVC) framework created
and maintained by Google (Angular bills itself as a Model-View-Whatever
framework, but for this book, the Whatever will be a controller). Angular treats
your view not as a static bit of HTML, but as a full-blown application. By
adopting the mind-set that your front end is a dynamic, connected interface,
and not a set of static pages, you open up many new possibilities.
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.
3. https://angularjs.org
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.
Here, the view isn’t just a description of static content, but a clear indication
of how it should behave. Intent is obvious—you can see how this works
without knowing the underlying implementation—and there’s a lot less code.
This is what a higher-level of abstraction like Angular gives you that would
otherwise be a mess with jQuery or just plain JavaScript.
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 we’ll cover 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 we’ll get to 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:
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
Bootstrap4 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 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 message.
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?
By just adding a few classes to some elements, you can have something pol-
ished and professional like this instead:
4. http://getbootstrap.com
In the next chapter we’ll do this to the login and registration forms provided
by the Devise gem. We’ll have a great-looking user sign-up and sign-in expe-
rience, without writing any CSS.
Typography
Just including Bootstrap in your application and using semantic HTML
will result 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 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. In Chapter 4, Create Clean Search Results,
on page 51 and Chapter 8, Design Great UIs with, on page 137, you’ll see just
how easy it is to create a customized UI without writing CSS, all thanks to
Bootstrap.
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
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.
For example, if you’re implementing a search, and it’s slow, you’ll 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.
SEARCH FEATURE
Search Ajax
Angular Bootstrap Form Calls
Results
View
Search
Rails Logic
Postgres Indexes
This holistic approach is how you’re going to learn these technologies. We’ll
build a Rails application together, adding features one at a time. These features
will demonstrate various aspects of the technologies we’re using.
To keep things simple, each chapter will focus on a single technology, and
we’ll complete features over several chapters. For example, in the next chapter
we’ll set up a simple registration system for our application and use Bootstrap
to style the views. In Chapter 2, Secure the Login Database, on page 25, we’ll
continue the feature but focus on using Postgres to add extra security at the
database layer. This will allow us to see each feature evolve as we bring in
relevant parts of the application stack. This will give you the confidence to
do the same for other features that you build in your own apps.
It’s also worth emphasizing the role of Rails in all of this. Although Rails
doesn’t have built-in APIs for using Postgres’s advanced features, nor support
for Angular’s way of structuring code, it doesn’t outright prevent our using
them. And Rails is a great middleware; probably one of the best.
Let’s learn about the Rails application that we’ll be building in this book.
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.
Bob
And they can click through and view or edit a customer’s data.
FOOTNOTE:
[A] I have presented here, together with ideas advanced by Mr. Hill,
others secured in fragmentary conversations with various farmers by
the way. These ideas seem to me to represent a body of accordant
thinking. It is fair to say that I also found among the farmers quite
another school of thought. This I shall try to present later with equal
fulness.
CHAPTER VI
IN A LOGGING CAMP
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com