Preface

Since its initial publication in 2010, the Ruby on Rails™ Tutorial has been one of the leading introductions to web development. In this best-selling tutorial, you’ll learn how to develop and deploy real, industrial-strength web applications with Ruby on Rails, the open-source web framework that powers top websites such as Hulu, GitHub, Shopify, and Airbnb. Newly updated for Rails 7, the Ruby on Rails Tutorial covers both specific aspects of Rails and general principles of web development, so what you learn here can be applied to a wide variety of different situations.

In the Ruby on Rails Tutorial, you’ll learn by doing through three applications of increasing sophistication. The first application follows a long-standing tradition in programming by developing (and deploying!) a simple app that displays the phrase “hello, world!” The second, a simplified “toy app”, develops an application consisting of users and posts, including a database to store user information.

Finally, the full sample app develops a professional-grade web application, including systems for user registration, login and authentication, account activation and password resets, and a follow/unfollow social layer inspired by Twitter. In the course of developing the main sample app, the Ruby on Rails Tutorial does everything “for real”, with good software-development practices throughout. This includes version control, testing and test-driven development, and deployment to production.

In addition to teaching you specific skills, the Ruby on Rails Tutorial also helps you develop technical sophistication—the seemingly magical ability to solve practically any technical problem. Technical sophistication includes concrete skills like version control and coding, as well as fuzzier skills like Googling the error message and knowing when to just reboot the darn thing. Throughout the Ruby on Rails Tutorial, we’ll have abundant opportunities to develop technical sophistication in the context of real-world examples.

Chapter by Chapter

Chapter 1 begins with a self-contained introduction to the basics of Ruby on Rails web development, including setting up a development environment, using Git and GitHub, and deploying to Heroku. The result is a simple but real “hello, world” application deployed to the live Web.

Chapter 2 uses a technique called “scaffolding” to make a rudimentary database-backed web application consisting of users and short (“micro”) posts. Although simple, the resulting “toy app” covers several key aspects of modern web development, including using databases to persist user data and following the model-view-controller (MVC) pattern to separate components of the application for maintainability and convenience.

Chapter 3 through Chapter 14 develop the tutorial’s full, professional-grade sample application. In Chapter 3, we’ll learn how to use Rails to create both static HTML pages and pages with a small amount of dynamic content. Along the way, we’ll get our first taste of automated testing, including an introduction to refactoring (changing the code’s form without changing its function).

Chapter 4 explores some elements of the Ruby programming language that are important for Rails, whether or not you have prior experience in the language. Topics include data structures, functions, blocks, and classes.

Chapter 5 starts filling in the layout defined in Chapter 3, including an introduction to Cascading Style Sheets (CSS) in Rails. Along the way, we’ll learn about partials, Rails routes, and the asset pipeline, including an introduction to Syntactically Awesome Style Sheets (Sass). Finally, this chapter adds an integration test to check that the links on the final layout are correct.

In Chapter 6, we’ll take the first step toward letting users sign up by creating a data model for users of our site, together with a way to store that data. The resulting users have names, email addresses, and secure passwords, as well as validations and tests for all of those attributes.

Chapter 7 uses an HTML form to submit user signup information to our application, which will then be used to create a new user and save its attributes to the database. At the end of the signup process, it’s important to render a profile page with the newly created user’s information, so we’ll begin by making a page for showing users, which will serve as the first step toward a full user profile page. Along the way, we’ll build on the work in previous chapters to write succinct and expressive integration tests.

In Chapter 8, we’ll implement a basic but still fully functional login system that maintains the logged-in state until the browser is closed by the user. The resulting authentication system will allow us to customize the site and implement an authorization model based on login status and identity of the current user.

In Chapter 9, we’ll build on the basic login system developed in Chapter 8 to add “remember me” functionality to our site. This involves using permanent cookies, first to automatically remember users when they log in, and then to optionally remember users with a “remember me” checkbox.

Chapter 10 starts by giving users the ability to update their profiles, which will also provide a natural opportunity to enforce an authorization model. Then we’ll make a listing of all users using sample data and pagination. Finally, we’ll add the ability to destroy users, wiping them clear from the database. Since we can’t allow just any user to have such dangerous powers, we’ll take care to create a privileged class of administrative users authorized to delete other users.

Chapter 11 adds an account-activation step to verify that the user controls the email address they used to sign up. This will involve associating an activation token and digest with a user, sending the user an email with a link including the token, and activating the user upon clicking the link. In the process, we’ll also have a chance to learn how to send email in Rails, both in development and in production.

Chapter 12 implements a password-reset option to handle the case of users forgetting their passwords. In addition to following similar steps to those covered in Chapter 11, implementing this feature will also require a web interface for sending the password-reset email and actually resetting the password.

Chapter 13 adds small posts, or “microposts”, to the sample application. The result is a full-strength version of the sketch from Chapter 2: a Micropost data model, associations with the User model, and the pages needed to manipulate and display the results. This includes the ability to include images in microposts, thereby constituting an introduction to image uploading and storage on Amazon S3.

In Chapter 14, we’ll complete the Ruby on Rails Tutorial sample application by adding a social layer that allows users to follow and unfollow other users, resulting in each user’s Home page displaying a status feed of the followed users’ microposts. Topics include modeling relationships between users, building the corresponding web interface (with an introduction to responsive web applications using Hotwire), and making a status feed. To help with the transition from tutorial to independent development, we’ll end with some pointers to more advanced resources.

Additional Features

The Ruby on Rails Tutorial includes a large number of exercises to help you test your understanding and to extend the material in the main text. The exercises include frequent hints and often include the expected answers, with exercise solutions available by separate subscription at www.railstutorial.org.

Final Thoughts

The Ruby on Rails Tutorial gives you a thorough and practical introduction to modern web development with Ruby on Rails. After learning the techniques covered in this tutorial, and especially after developing your technical sophistication, you’ll know everything you need to develop custom database-backed web applications and deploy them to the live Web. You’ll also be ready for a huge variety of other resources, including books, blogs, and online documentation. The resulting skillset will put you in a great position to get a job as a web developer, start a career as a freelancer, or even found a company of your own.

Learn Enough Scholarships

The Ruby on Rails Tutorial is part of Learn Enough, which is committed to making a technical education available to as wide a variety of people as possible. As part of this commitment, in 2016 Learn Enough created the Learn Enough Scholarship program.1 Scholarship recipients get free or deeply discounted access to the Learn Enough All Access subscription, which includes online book content, embedded videos, exercises, and community exercise answers for all of the Learn Enough courses (including the full Ruby on Rails Tutorial).

1. https://www.learnenough.com/scholarship

As noted in a 2019 RailsConf Lightning Talk,2 the Learn Enough Scholarship application process is incredibly simple: Just fill out a confidential text area telling us a little about your situation. The scholarship criteria are generous and flexible—we understand that there are an enormous number of reasons for wanting a scholarship, from being a student, to being between jobs, to living in a country with an unfavorable exchange rate against the U.S. dollar. Chances are that if you feel like you’ve got a good reason, we’ll think so, too.

2. https://www.learnenough.com/scholarship-talk

So far, Learn Enough has awarded more than 2,500 scholarships to aspiring developers around the country and around the world. To apply, visit the Learn Enough Scholarship page at www.learnenough.com/scholarship. Maybe the next scholarship recipient could be you!

Register your copy of Ruby on Rails™ Tutorial, Seventh Edition, on the InformIT site for convenient access to updates and/or corrections as they become available. To start the registration process, go to informit.com/register and log in or create an account. Enter the product ISBN (9780138049843) and click Submit. Look on the Registered Products tab for an Access Bonus Content link next to this product, and follow that link to access any available bonus materials. If you would like to be notified of exclusive offers on new editions and updates, please check the box to receive email from us.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.21.205