AngularJS with Ruby on Rails

AngularJS, Rails, and Production

Buy the Book: Rails, Angular, Postgres, and Bootstrap: Powerful, effective, efficient, full-stack web development

The latest wave of JavaScript frameworks present an interesting problem to experienced Rails developers. On their own, these frameworks can only do so much, since they are designed to run on the client-side, in a browser. This means that for any real application you might create, you need a back-end.

Rails is a terrific back-end, however it wasn't designed with a JavaScript framework like AngularJS in mind. Rails' view of the world is serving up pages and HTML. Rich Javascript-based single-page applications aren't something Rails encourages.

AngularJS is a terrific front-end. It supports testability, clean code organization, and has a simple object model. It's supremely powerful but, of course, wasn't designed with Rails in mind—it's back-end agnostic.

The result is that there is no “Rails Way” for managing the front-end assets needed to create a rich JavaScript application using AngularJS.

This mini-book is going to change that. We're going to see step-by-step instructions for building a Rails app with Angular, and getting it deployed to production. That means we'll properly configure the asset pipeline, provide a solution for managing front-end assets, and see how to integrate testing the front-end code into your app.

This is not a Rails or Angular tutorial. If you'd like to learn Angular, I would suggest completing their tutorial. Don't just read it, type out the code. Run the code. Tweak the code. It only takes an hour or so, and it'll give the confidence you need to start using Angular (that's what I did).

Once you're familiar enough with Angular to start building an app, you'll find there are a lot of unanswered questions:

I was able to find answers by piecing together information from Stack Overflow and various blog posts. You shouldn't have to do that.

How this book is organized

This mini-book is broken up into four major parts:

The technologies we'll be using:

When we're done, you'll know exactly what you need to do to get Angular into your Rails app in a way that supports sustained development and deployment. You'll be able to get to your code more quickly and confidently.

What you'll need

The code in this book is pulled from a git repository containing the Rails app we'll be building. The console output we'll see is generated directly from that code, so you should be able to follow along easily.

I'd still recommend you follow along at your terminal and editor. Even though you will just be typing in what you see, it'll get your fingers used to the workflow and code involved in a a Rails-powered Angular app.

All you'll need:

The app we'll see in this book was originally developed on OS X, so some terminal commands might be different if you are on Windows. Please let me know what those differences are.

With that out of the way, let's get started!