Easy Active Record for Rails Developers (The Book + ArcadeNomad Project Source Code)
Easy Active Record for Rails Developers
Master Rails Active Record and Have a Blast Doing It!
About the Book
Easy Active Record for Rails Developers is the ultimate guide to mastering building database-driven Rails applications using the powerful Active Record ORM Framework. By loosely following along with the development of a fun, web application for retro arcade aficionados, you’ll learn how to:
- Understand the importance differences between and implement the belongs_to, has_one, has_many, has_and_belongs_to_many and has_many :through model associations
- Properly validate, filter and manipulate your application’s model data
- Manage model schemas using Active Record’s powerful migrations tool
- Create and integrate complex web forms, including those involving nested models
- Deftly traverse associations using includes and joins
- Monitor, debug and optimize your queries
- Integrate user registration and authentication features using the Devise gem
So far, I’m liking the no fluff, straight to the point approach! - Don Pawlowski, Developer, Designing Interactive
Table of Contents
Easy Active Record for Rails Developers is divided into six chapters covering the fundamental topics most critical to today's Rails developer.
Chapter 1. Introducing Models, Schemas and MigrationsIn this opening chapter we'll get acquainted with many of the fundamental Active Record features you'll use throughout your project's lifetime. You'll learn how to create the models used to manage the application's business logic and provide convenient interfaces to the underlying database. You'll also learn how to use a great feature called *migrations* to create and evolve your database schema. The chapter concludes with a section explaining how to begin testing your models with RSpec and factory_girl
Chapter 2. Loading, Validating and Manipulating DataIn this chapter you'll learn how to easily load, or *seed*, your application with an initial data set, as well as create and manipulate data. Of course, because we'll want to eliminate all possibilities of incomplete or invalid data from being persisted to the database, you'll also learn how to enhance your application models using a variety of *validators*. Additionally, we'll build on the introductory model testing material presented in the previous chapter. Notably, you'll learn how to create tests for ensuring you've properly fortified your models with enough validators to ensure unwanted data can't slip through the cracks.
Chapter 3. Querying the DatabaseIn Chapter 2 you learned how to load seed data and create records, now it's time to begin querying that data! In this chapter I'll introduce you to Active Record's array of extraordinarily powerful query features. By the conclusion of this chapter you'll know how to efficiently query for all records, retrieve a specific record according to primary key, select only desired columns, order, group and limit results, retrieve random records, and paginate results. You'll also learn how to integrate these queries with the application controller and view to create listing and detail pages. Always striving towards writing readable code, we'll also enhance the models using a fantastic feature known as a *scope*.
Chapter 4. Introducing AssociationsBuilding and navigating table relations is an standard part of the development process even when working on the most unambitious of projects, yet this task is often painful when working with many web frameworks. Not so with Rails. Thanks to a fantastic feature known as *Active Record Associations*, defining and traversing these associations is a fairly trivial matter. In this chapter I'll show you how to define, manage, and interact with the `belongs_to`, `has_one`, `has_many`, `has_many :through`, and the `has_and_belongs_to_many` associations.
Chapter 5. Mastering Web FormsYour application's web forms will preferably interact with the models, meaning you'll require a solid grasp on Rails' form generation and processing capabilities in order to integrate with your models in the most efficient way possible. While creating simple forms is fairly straightforward, things can complicated fast when implementing more ambitious solutions such as forms involving multiple models. In this chapter I'll go into extensive detail regarding how you can integrate forms into your Rails applications, covering both Rails' native form building solutions as well as several approaches offered by popular gems.
Chapter 6. Debugging and Optimizing Your ApplicationWhile it's fun to brag about all of your project's gloriously cool features, they came at great expense of your time and brainpower. Much of the effort was likely grunt work, spent figuring out problems such as why a query was running particularly slow or the reason a complex association wasn't working as expected. This important but decidedly unglamourous part of programming is something I try to minimize on every occasion by relying on a number of tools and techniques that can automate much of the analysis and debugging process. In this chapter I'll introduce you to several of my favorite solutions for debugging and optimizing Rails applications.
Chapter 7. Integrating User Accounts with DeviseOffering users the opportunity to create an account opens up a whole new world of possibilities in terms of enhanced interactivity and the opportunity to create and view custom content. Yet there are quite a few moving parts associated with integrating even basic account features, including account registration, secure password storage, sign in, sign out and password recovery interfaces, and access restriction. Fortunately the fantastic Devise gem greatly reduces the amount of work otherwise required to implement account creation, authorization and management features, and in this chapter I’ll introduce you to many of the wonderful features this gem has to offer.
Chapter 8. Powerful Active Record PluginsRuby on Rails is such a powerful solution thanks in large part to its enormous ecosystem. You're probably familiar with prominent gems such as Devise, RSpec, and FriendlyId, but there are also much more focused gems capable of extending specific parts of Rails, including templating (such as Redcarpet) and e-mail (see the popular Mail gem). So too can you extend Active Record in a variety of interesting and useful ways, and in this chapter I'll introduce you to a few of my favorite gems, including Acts As Taggable On, Decent Exposure, and Geocoder.
Packages
The Book + ArcadeNomad Project Source Code
This package includes the book in addition to *all* of the source code and sample data used to power the ArcadeNomad demo project.
PDF
EPUB
WEB
English
The Book
This package includes the book, and of course all updates are free to existing readers forever!
PDF
EPUB
WEB
English
Table of Contents
-
Introduction
- Introducing Active Record
- About this Book
- Introducing the ArcadeNomad Theme Project
- About the Author
- Errata and Suggestions
-
Chapter 1. Introducing Models, Schemas and Migrations
- Creating the ArcadeNomad Project
- Installing the RSpec, FactoryGirl and Database Cleaner Gems
- Introducing Rails Models
- Rails Models are Plain Old Ruby Objects
- Introducing Migrations
- Testing Your Models
- Conclusion
-
Chapter 2. Loading, Validating and Manipulating Data
- Seeding and Updating Your Database
- Callbacks
- Introducing Rails Validators
- Creating, Updating, and Deleting Records
- Deleting and Destroying Records
- Conclusion
-
Chapter 3. Querying the Database
- Finding Data
- Paginating Results
- Creating a Prettier URL with FriendlyId
- Introducing Scopes
- Conclusion
-
Chapter 4. Introducing Associations
- Normalizing Your Database
- Introducing Associations
- Eager Loading of Associations
- Polymorphic Models
- Conclusion
-
Chapter 5. Mastering Web Forms
- Web Form Fundamentals
- Rails Routing and Forms
- Creating a Simple Contact Form
- Managing Your Application Data
- Useful Forms-Related Gems
- Conclusion
-
Chapter 6. Debugging and Optimizing Your Application
- Debugging Your Application
- Optimizing Your Application
- Summary
-
Chapter 7. Integrating User Accounts with Devise
- Installing Devise
- Creating the User Account Model
- Adding User Registration Capabilities
- Adding User Sign In and Sign Out Capabilities
- Adding User Account Management Capabilities
- Adding Password Recovery Capabilities
- Restricting Access to Authenticated Users
- Commonplace Devise Customizations
- Conclusion
-
Chapter 8. Powerful Active Record Plugins
- Tagging Your Content Using the Acts As Taggable On Gem
- Cleaning Up Your Controllers with the Decent Exposure Gem
- Geocoding Your Models
- Summary
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned$12,307,240writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
Personal Finance
Jason AndersonThis textbook provides an in-depth analysis on personal finance that is both practical and straightforward in its approach. It has been written in such a way that the readers can gain knowledge without getting overwhelmed by the technical terms. Suitable for both beginners and advanced learners.
Getting to Know IntelliJ IDEA
Trisha Gee and Helen ScottIf we treat our IDE as a text editor, we are doing ourselves a disservice. Using a combination of tutorials and a questions-and-answers approach, Getting to Know IntelliJ IDEA will help you find ways to use IntelliJ IDEA that enable you to work comfortably and productively as a professional developer.
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Mastering STM32 - Second Edition
Carmine NovielloWith more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.
Stats One
William FooteMachine Learning Q and AI
Sebastian Raschka, PhDHave you recently completed a machine learning or deep learning course and wondered what to learn next? With 30 questions and answers on key concepts in machine learning and AI, this book provides bite-sized bits of knowledge for your journey to becoming a machine learning expert.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Gradual Modularization for Ruby and Rails
Stephan HagemannGet yourself a new tool to manage your Rails application and your growing engineering organization! Prevent the ball-of-mud (and fix it!). Go for microservices or SOA if it makes sense not just because you don't have any other tool. Do all this through a low-overhead tool: packages. Enable better conversations to make practical changes today.
Top Bundles
- #1
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #3
1500 QUIZ COMMENTATI (3 libri)
3 Books
Tre libri dei QUIZ MMG Commentati al prezzo di DUE! I QUIZ dei concorsi ufficiali di Medicina Generale relativi agli anni: 2000-2001-2003-2012-2013-2014-2015-2016-2017-2018-2019-2020-2021 +100 inediti Raccolti in unico bundle per aiutarvi nello studio e nella preparazione al concorso. All'interno di ogni libro i quiz sono stati suddivisi per... - #4
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #5
Practical FP in Scala + Functional event-driven architecture
2 Books
Practical FP in Scala (A hands-on approach) & Functional event-driven architecture, aka FEDA, (Powered by Scala 3), together as a bundle! The content of PFP in Scala is a requirement to understand FEDA so why not take advantage of this bundle!? - #7
Linux Administration Complet
4 Books
Ce lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité... - #9
Development and Deployment of Multiplayer Online Games, Part ARCH. Architecture (Vol. I-III)
3 Books
What's the Big Idea? The idea behind this book is to summarize the body of knowledge that already exists on multiplayer games but is not available in one single place.And quite a fewof the issues discussed within this series (planned as three nine volumes ~300 pages each), while known in the industry, have not been published at all (except for... - #10
Modern C++ Collection
3 Books
Get All about Modern C++C++ Standard Library, including C++20Concurrency with Modern C++, including C++20C++20Each book has about 200 complete code examples. Updates are included. When I update one of the books, you immediately get the updated bundle. You can expect significant updates to each new C++ standard (C++23, C++26, .. ) and also...