Rails 4 in Action
Revised Edition of Rails 3 in Action
Ryan Bigg, Yehuda Katz, Steve Klabnik, and Rebecca Skinner
  • August 2015
  • pBook available Sep 10, 2115
  • ISBN 9781617291098
  • 576 pages
  • printed in black & white

There's no better source for Rails 4. This book blows away the competition.

Damien White, Visoft, Inc.

PRODUCT ALERT:

pBook coming September 10, 2015

ePub + kindle formats coming September 14, 2015

Rails 4 in Action is a comprehensive introduction to Rails that guides you hands-on through all you'll need to become a competent and confident Rails developer. In it, you'll master Rails 4 by developing a ticket-tracking application that includes RESTful routing, authentication and authorization, file uploads, email, and more.

Table of Contents show full

preface

acknowledgments

about this book

about the authors

author online

about the cover illustration

1. Ruby on Rails, the framework

1.1. Ruby on Rails overview

1.1.1. Benefits

1.1.2. Ruby gems

1.1.3. Common terms

1.1.4. Rails in the wild

1.2. Developing your first application

1.2.1. Installing Rails

1.2.2. Generating an application

1.2.3. Starting the application

1.2.4. Scaffolding

1.2.5. Migrations

1.2.6. Viewing and creating purchases

1.2.7. Validations

1.2.8. Routing

1.2.9. Updating

1.2.10. Deleting

1.3. Summary

2. Testing saves your bacon

2.1. Using TDD and BDD to save your bacon

2.2. Test-driven development basics

2.2.1. Writing your first test

2.2.2. Saving bacon

2.3. Behavior-driven development basics

2.3.1. Introducing RSpec

2.3.2. Writing your first spec

2.3.3. Running the spec

2.3.4. Much more bacon

2.3.5. Expiring bacon

2.4. Summary

3. Developing a real Rails application

3.1. First steps

3.1.1. The application story

3.1.2. Laying the foundations

3.2. Version control

3.2.1. Getting started with GitHub

3.2.2. Configuring your Git client

3.3. Application configuration

3.3.1. The Gemfile and generators

3.3.2. Database configurations

3.4. Beginning your first feature

3.4.1. Creating projects

3.4.2. Defining a controller action

3.4.3. RESTful routing

3.4.4. Committing changes

3.4.5. Setting a page title

3.4.6. Validations

3.5. Summary

4. Oh CRUD!

4.1. Viewing projects

4.1.1. Introducing Factory Girl

4.2. Editing projects

4.2.1. The edit action

4.2.2. The update action

4.3. Deleting projects

4.4. What happens when things can’t be found

4.4.1. Visualizing the error

4.4.2. Handling the ActiveRecord::RecordNotFound exception

4.5. Styling the application

4.5.1. Installing Bootstrap

4.5.2. Improving the page’s header

4.5.3. Improving the show view

4.5.4. Semantic styling

4.5.5. Using Simple Form

4.5.6. Adding a navigation bar

4.5.7. Responsive styling

4.6. Summary

5. Nested resources

5.1. Creating tickets

5.1.1. Nested routing helpers

5.1.2. Creating a tickets controller

5.1.3. Demystifying the new action

5.1.4. Defining a has_many association

5.1.5. Creating tickets in a project

5.1.6. Finding tickets scoped by project

5.1.7. Ticket validations

5.2. Viewing tickets

5.2.1. Listing tickets

5.2.2. Culling tickets

5.3. Editing tickets

5.3.1. The ticket-editing spec

5.3.2. Adding the edit action

5.3.3. Adding the update action

5.4. Deleting tickets

5.5. Summary

6. Authentication

6.1. Using Devise

6.2. Adding sign-up

6.3. Adding sign-in and sign-out

6.3.1. Adding sign-in

6.3.2. Adding sign-out

6.3.3. Styling the Devise views

6.4. Linking tickets to users

6.4.1. Fixing the failing four features

6.5. Summary

7. Basic access control

7.1. Turning users into admins

7.1.1. Adding the admin field to the users table

7.1.2. Creating the first admin user

7.2. Controllern namespacing

7.2.1. Generating a namespaced controller

7.2.2. Testing a namespaced controller

7.2.3. Moving functionality into the admin namespace

7.4. Namespace-based CRUD

7.4.1. The index action

7.4.2. The new action

7.4.3. The create action

7.4.4. Creating admin users

7.4.5. Editing users

7.4.6. The edit and update actions

7.4.7. Archiving users

7.4.8. Ensuring that you can’t archive yourself

7.4.9. Preventing archived users from signing in

7.5. Summary

8. Fine-grained access control

8.1. Project-viewing permission

8.1.1. Assigning Roles in specs

8.1.2. Creating the Role model

8.1.3. Setting up Pundit

8.1.4. Testing the ProjectPolicy

8.1.5. Fixing what you broke

8.1.6. Handling authorization errors

8.1.7. One more thing

8.2. Project-updating permission

8.2.1. Testing the ProjectPolicy again

8.2.2. Applying the authorization

8.3. Ticket-viewing permission

8.3.1. Refactoring policy specs

8.3.2. Testing the TicketPolicy

8.3.3. Refactoring policies

8.4. Ticket-creation permission

8.4.1. Testing the TicketPolicy …​ again

8.4.2. Applying the authorization

8.5. Ticket-updating permission

8.5.1. Testing the TicketPolicy …​ turbocharged

8.5.2. Implementing controller authorization

8.6. Ensuring authorization for all actions

8.7. Assigning roles to users

8.7.1. Planning the permission screen with a feature spec

8.7.2. The roles screen

8.7.3. Building a list of projects in a select box

8.7.4. Processing the submitted role data

8.7.5. Saving roles of new users

8.8. Summary

9. File uploading

9.1. Attaching a file

9.1.1. A feature featuring files

9.1.2. Enter, stage right: CarrierWave

9.1.3. Using CarrierWave

9.1.4. Persisting uploads when redisplaying a form

9.2. Attaching many files

9.2.1. Testing multiple-file upload

9.2.2. Implementing multiple-file upload

9.2.3. Using nested attributes

9.3. Serving files through a controller

9.3.1. Testing existing functionality

9.3.2. Protecting attachments

9.3.3. Showing your attachments

9.3.4. Public attachments

9.3.5. Privatizing attachments

9.4. Using JavaScript

9.4.1. JavaScript testing

9.4.2. Cleaning the database

9.4.3. Introducing jQuery

9.4.4. Adding more files with JavaScript

9.5. Responding to an asynchronous request

9.5.1. Appending new content to the form

9.5.2. Sending parameters for an asynchronous request

9.6. Summary

10. Tracking state

10.1. Leaving a comment

10.1.1. The comment form

10.1.2. The comments controller

10.2. Changing a ticket’s state

10.2.1. Creating the State model

10.2.2. Selecting states

10.2.3. Setting a default state for a comment

10.2.4. Seeding your app with states

10.3. Tracking changes

10.3.1. Ch-ch-changes

10.3.2. Another c-c-callback

10.3.3. Displaying changes

10.3.4. Styling states

10.4. Managing states

10.4.1. Adding additional states

10.4.2. Defining a default state

10.4.3. Applying the default state

10.4.4. Setting a default state in seed states

10.5. Locking down states

10.5.1. Hiding a select box

10.5.2. Defining the change_state permission

10.5.3. Hacking a form

10.5.4. Ignoring a parameter

10.6. Summary

11. Tagging

11.1. Creating tags

11.1.1. The tag-creation feature

11.1.2. Showing tags

11.1.3. Defining the tags association

11.1.4. The Tag model

11.1.5. Displaying a ticket’s tags

11.2. Adding more tags

11.2.1. Adding tags through a comment

11.3. Tag restriction

11.3.1. Testing tag restriction

11.3.2. Tags are allowed, for some

11.4. Deleting a tag

11.4.1. Testing tag deletion

11.4.3. Removing a tag from the page

11.5. Finding tags

11.5.2. Searching by tags

11.5.3. Searching by state

11.6. Summary

12. Sending email

12.1. Sending ticket notifications

12.1.1. Automatically watching a ticket

12.1.2. Using service classes

12.1.3. Defining the watchers association

12.1.4. Introducing Action Mailer

12.1.5. An Action Mailer template

12.1.6. Testing with mailer specs

12.2. Subscribing to updates

12.2.1. Testing comment subscription

12.2.2. Automatically adding the commenter to the watchers list

12.2.3. Unsubscribing from ticket notifications

12.3. Summary

13. Deployment

13.1. What is deployment?

13.2. Simple deployment from Heroku

13.2.1. Signing up

13.2.2. Provisioning an app

13.3. Twelve-factor apps

13.3.1. Configuration

13.3.2. Processes

13.3.3. Combining Heroku and S3

13.4. Deploying Ticketee

13.4.1. Fixing deployment issues

13.4.2. Fixing CarrierWave file uploads

13.4.3. Deploying is hard

13.5. Continuous deployment with Travis CI

13.5.1. Configuring Travis

13.5.2. Deployment

13.6. Sending emails

13.7. Summary

14. Designing an API

14.1. An overview of APIs

14.1.1. A practical examples

14.2. Using ActiveModel::Serializers

14.2.1. Getting your hands dirty

14.3. API authentication and authorization

14.3.1. The API namespace

14.3.2. A small tangent on inflections

14.3.3. Getting back to your API

14.4. It’s not a party without …​ HTTParty

14.5. Handling errors

14.5.1. Authenticating with a blank token

14.5.2. Permission denied

14.5.3. Validation errors

14.6. A small refactoring

14.7. Summary

15. Rack-based applications

15.1. Building Rack applications

15.1.1. A basic Rack application

15.1.2. Let’s increase the heartbeat

15.1.3. You’re not done yet

15.2. Building bigger Rack applications

15.2.1. You’re breaking up

15.2.2. Running a combined Rack application

15.3. Mounting a Rack application with Rails

15.3.1. Mounting Heartbeat

15.3.2. Introducing Sinatra

15.3.3. The API, by Sinatra

15.3.4. Basic error-checking

15.4. Middleware

15.4.1. Middleware in Rails

15.4.2. Crafting middleware

15.4.3. Using middleware

15.5. Summary

Appendixes

Appendix A: Installation guide

A.1. Windows

A.2. Mac OS X

A.3. Linux

Appendix B: Why Rails?

B.1. The sense of community

B.2. The speed and ease of development

B.3. RubyGems

B.4. The emphasis on testing

About the book

Rails is a full-stack, open source web framework powered by Ruby. Now in version 4, Rails is mature and powerful, and to use it effectively you need more than a few Google searches. You’ll find no substitute for the guru’s-eye-view of design, testing, deployment, and other real-world concerns that this book provides.

Rails 4 in Action is a hands-on guide to the subject. In this fully revised new edition, you’ll master Rails 4 by developing a ticket-tracking application that includes RESTful routing, authentication and authorization, file uploads, email, and more. Learn to design your own APIs and successfully deploy a production-quality application. You’ll see test-driven development and behavior-driven development in action throughout the book, just like in a top Rails shop.

What's inside

  • Creating your own APIs
  • Using RSpec and Capybara
  • Emphasis on test-first development
  • Fully updated for Rails 4

About the reader

For readers of this book, a background in Ruby is helpful but not required. No Rails experience is assumed.

About the authors

Ryan Bigg, Yehuda Katz, Steve Klabnik, and Rebecca Skinner are contributors to Rails and active members of the Rails community.


combo - Preorder $49.99 pBook + eBook
eBook $39.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks

A gentle yet thorough guide to Rails 4.

William Wheeler, ProData Computer Services

Very clear, with excellent examples. A must-read for everyone in the Rails world.

Michele Bursi, Nokia

Well-written, intuitive, and easy to understand.

Lee Allen, SecuritySession.com