Learning Rails 5

Book description

If you’re a web developer or designer ready to learn Ruby on Rails, this hands-on guide is the ideal way to get started. Rather than toss you into the middle of the framework’s Model-View-Controller architecture, as many books do, Learning Rails 5 begins with the foundations of the Web you already know.

You’ll learn how to create something visible with Rails’ view layer before diving into the more difficult inner layers: the database models and controller code. All you need to begin your Rails journey is HTML experience. Each chapter includes exercises and review questions to test your understanding as you go.

  • Present content by building an application with a basic view and a simple controller
  • Build forms and process their results, progressing from simple to more complex
  • Use Rails scaffolding and REST to build effective applications quickly
  • Connect forms to models and create code that maps directly to database structures
  • Build applications that combine data from multiple tables
  • Use migrations to track changes to your database over time
  • Add common elements such as sessions, cookies, and authentication

Publisher resources

View/Submit Errata

Table of contents

  1. Foreword
  2. Preface
    1. Who This Book Is For
    2. Who This Book Is Not For
    3. What You’ll Learn
    4. Ruby and Rails Style
    5. Other Options
    6. Rails Versions
    7. If You Have Problems Making Examples Work
    8. If You Like (or Don’t Like) This Book
    9. Conventions Used in This Book
    10. Using Code Examples
    11. O’Reilly Safari
    12. How to Contact Us
    13. Acknowledgments
  3. 1. Starting Up Ruby on Rails
    1. If You Run Windows, You’re Lucky
    2. Getting Started at the Command Line
    3. Starting Up Rails
    4. Test Your Knowledge
      1. Quiz
      2. Answers
  4. 2. Rails on the Web
    1. Creating Your Own View
    2. What Are All Those Folders?
    3. Adding Some Data
    4. How Hello World Works
    5. Adding Logic to the View
    6. Test Your Knowledge
      1. Quiz
      2. Answers
  5. 3. Adding Web Style
    1. I Want My CSS!
    2. Specifying Stylesheets
    3. Creating a Layout for a Controller
    4. Choosing a Layout from a Controller
    5. Sharing Template Data with the Layout
    6. Setting a Default Page
    7. Test Your Knowledge
      1. Quiz
      2. Answers
  6. 4. Managing Data Flow: Controllers and Models
    1. Getting Started, Greeting Guests
    2. Application Flow
    3. Keeping Track: A Simple Guestbook
      1. Connecting to a Database Through a Model
      2. Connecting the Controller to the Model
    4. Finding Data with ActiveRecord
    5. Test Your Knowledge
      1. Quiz
      2. Answers
  7. 5. Accelerating Development with Scaffolding and REST
    1. A First Look at Scaffolding
    2. REST and Controller Best Practices
      1. Websites and Web Applications
      2. Toward a Cleaner Approach
    3. Examining a RESTful Controller
      1. index: An Overview of Data
      2. show: Just One Row of Data and the Before Filter
      3. new: A Blank Set of Data Fields
      4. edit: Hand Me That Data, Please
      5. create: Save Something New
      6. Put This Updated Record In
      7. Destroy It
    4. Escaping the REST Prison
    5. Test Your Knowledge
      1. Quiz
      2. Answers
  8. 6. Presenting Models with Forms
    1. More Than a Name on a Form
    2. Generating HTML Forms with Scaffolding
    3. Form as a Wrapper
    4. Creating Text Fields and Text Areas
    5. Labels
    6. Creating Checkboxes
    7. Creating Radio Buttons
    8. Creating Selection Lists
    9. Dates and Times
    10. Creating Helper Methods
    11. Test Your Knowledge
      1. Quiz
      2. Answers
  9. 7. Strengthening Models with Validation
    1. Without Validation
    2. The Original Model
    3. The Power of Declarative Validation
    4. Managing Secrets
      1. Customizing the Message
      2. Limiting Choices
      3. Testing Format with Regular Expressions
      4. Seen It All Before
      5. Numbers Only
    5. A Place on the Calendar
      1. Testing for Presence
    6. Beyond Simple Declarations
      1. Test It Only If
      2. Do It Yourself
    7. Test Your Knowledge
      1. Quiz
      2. Answers
  10. 8. Improving Forms
    1. Adding a Picture by Uploading a File
      1. File Upload Forms
      2. Model and Migration Changes
      3. Results
    2. Standardizing Your Look with Form Builders
      1. Supporting Your Own Field Types
      2. Adding Automation
      3. Integrating Form Builders and Styles
    3. Test Your Knowledge
      1. Quiz
      2. Answers
  11. 9. Developing Model Relationships
    1. Connecting Awards to Students
      1. Establishing the Relationship
      2. Supporting the Relationship
    2. Connecting Students to Awards
      1. Removing Awards When Students Disappear
      2. Counting Awards for Students
    3. Nesting Awards in Students
      1. Changing the Routing
      2. Changing the Controller
      3. Changing the Award Views
      4. Connecting the Student Views
      5. Is Nesting Worth It?
    4. Many-to-Many: Connecting Students to Courses
      1. Creating Tables
      2. Connecting the Models
      3. Adding to the Controllers
      4. Adding Routing
      5. Supporting the Relationship Through Views
    5. What’s Missing?
    6. Test Your Knowledge
      1. Quiz
      2. Answers
  12. 10. Managing Databases with Migrations
    1. What Migrations Offer You
    2. Migration Basics
      1. Migration Files
      2. Running Migrations Forward and Backward
    3. Inside Migrations
      1. Working with Tables
      2. Data Types
      3. Working with Columns
      4. Indexes
      5. Other Opportunities
    4. Test Your Knowledge
      1. Quiz
      2. Answers
  13. 11. Debugging
    1. Creating Your Own Debugging Messages
    2. Raising Exceptions
    3. Logging
    4. Working with Rails from the Console
    5. Debug and Debugger
    6. Test Your Knowledge
      1. Quiz
      2. Answers
  14. 12. Testing
    1. Test Mode
    2. Testing the Students App
    3. Setting Up a Test Database with Fixtures
    4. Model Testing
    5. Controller Testing
      1. Calling Controllers
      2. Testing Responses
      3. Dealing with Nested Resources
    6. Integration Testing
    7. Beyond the Basics
    8. Test Your Knowledge
      1. Quiz
      2. Answers
  15. 13. Sessions and Cookies
    1. Getting Into and Out of Cookies
    2. Storing Data Between Sessions
    3. Test Your Knowledge
      1. Quiz
      2. Answers
  16. 14. Users and Authentication
    1. The Sign-up Process
    2. Wiring Authentication to Your Application
    3. Classifying Users
    4. More Options
    5. Test Your Knowledge
      1. Quiz
      2. Answers
  17. 15. Routing
    1. Creating Routes to Interpret URIs
      1. Specifying Routes
      2. Globbing
      3. Regular Expressions and Routing
      4. A Domain Default with root
      5. Mapping Resources
      6. Nesting Resources
      7. Route Order and Priority
      8. Checking the Map
    2. Generating URIs from Views and Controllers
      1. Pointing url_for in the Right Direction
      2. Adding Options
    3. Infinite Possibilities
    4. Test Your Knowledge
      1. Quiz
      2. Answers
  18. 16. From CSS to Sass
    1. Getting Started
    2. Sassy Style
      1. Variables
      2. Mixins
      3. Nesting
    3. Making Everything Work Together
      1. Becoming Sassier
    4. Test Your Knowledge
      1. Quiz
      2. Answers
  19. 17. Managing Assets and Bundles
    1. The Junk Drawer
      1. Sprockets
      2. Dissecting the Pipeline
      3. Putting It All Together
      4. Bundler
    2. Test Your Knowledge
      1. Quiz
      2. Answers
  20. 18. Sending Code to the Browser: JavaScript and CoffeeScript
    1. Sending JavaScript to the Browser
    2. Simplifying with CoffeeScript
      1. Have Some Sugar with Your CoffeeScript
      2. Converting to CoffeeScript
    3. Test Your Knowledge
      1. Quiz
      2. Answers
  21. 19. Mail in Rails
    1. Sending Mail Messages
    2. Previewing Mail
    3. Receiving Mail
      1. Setup
      2. Processing Messages
    4. Test Your Knowledge
      1. Quiz
      2. Answers
  22. 20. Pushing Further into Rails
    1. Changing to Production Mode
    2. Deploying Is Much More Than Programming
    3. Joining the Rails Ecosystem
      1. Keep Up with Rails
      2. Ruby
      3. Working with and Around Rails
      4. Keep Exploring
  23. A. An Incredibly Brief Introduction to Ruby
    1. How Ruby Works
    2. How Rails Works
    3. Getting Started with Classes and Objects
    4. Comments
    5. Variables, Methods, and Attributes
      1. Variables
      2. Methods
      3. Attributes
    6. Logic and Conditionals
      1. Operators
      2. if, else, unless, and elsif
      3. Shorthand if/else
      4. case and when
      5. Loops
      6. Many More Possibilities
  24. B. An Incredibly Brief Introduction to Relational Databases
    1. Tables of Data
      1. Connecting Tables
      2. Using Tables to Connect Tables
      3. Granularity
    2. Databases, Tables, and Rails
  25. C. An Incredibly Brief Guide to Regular Expressions
    1. What Regular Expressions Do
    2. Starting Small
    3. The Simplest Expressions: Literal Strings
    4. Character Classes
    5. Escaping
    6. Modifiers
    7. Anchors
    8. Sequences, Repetition, Groups, and Choices
    9. Greed
    10. More Possibilities
  26. D. Glossary
    1. Speaking in Rails
  27. Index

Product information

  • Title: Learning Rails 5
  • Author(s): J. Mark Locklear, Eric J Gruber, Barnabas Bulpett
  • Release date: August 2016
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491926154