Tens of thousands of developers have used this award-winning book to learn Rails. It's a broad, far-reaching tutorial and reference that's recommended by the Rails core team. If you're new to Rails, you'll get step-by-step guidance. If you're an experienced developer, this book will give you the comprehensive, insider information you need.
Rails has evolved over the years, and this book has evolved along with it. We still start with a step-by-step walkthrough of building a real application, and in-depth chapters look at the built-in Rails features.
This edition now gives new Ruby and Rails users more information on the Ruby language and takes more time to explain key concepts throughout. Best practices on how to apply Rails continue to change, and this edition keeps up. Examples use cookie backed sessions, HTTP authentication, and Active Record-based forms, and the book focuses throughout on the right way to use Rails. Additionally, this edition now reflects Ruby 1.
Available in epub, mobi, and PDF direct from the publisher and in paperback from fine bookstores worldwide. Find indie bookstores in the U. Find indie bookstores around the world. Ruby on Rails helps you produce high-quality, beautiful-looking web applications quickly.
You concentrate on creating the application, and Rails takes care of the details. Tens of thousands of developers have used this award-winning book to learn Rails. Rails has evolved over the years, and this book has evolved along with it. We still start with a step-by-step walkthrough of building a real application, and in-depth chapters look at the built-in Rails features. This edition now gives new Ruby and Rails users more information on the Ruby language and takes more time to explain key concepts throughout.
This is the main reason we need certain software installed before we get to Ruby. You should see a version of the form It should show you something like 1.
Now we can install Ruby and Rails! You need Ruby 2. This also allows you to use To do that, you either need to tell rbenv to use Ruby 2. You should see 2. Next, we will install Rails itself. You should see 6.
The last thing to install is ChromeDriver. This completes the setup of Ruby and Rails. The rest of this chapter will outline other software you might need to do development. Choosing a Rails Version The previous instructions helped you install the version of Rails used by the examples in this book. But occasionally you might not want to run that version. For example, a newer version with some fixes or new features might become available. If either of these situations applies to you, you need to be aware of a few things.
It should return 6. The Command Line We do a lot of work at the command line. Although an increasing number of GUI tools help generate and manage a Rails application, we find the command line is still the most powerful place to be. So-called tab completion is standard on Unix shells such as Bash and Zsh. It allows you to type the first few characters of a filename, hit Tab , and have the shell look for and complete the name based on matching files. Version Control We keep all our work in a version control system currently Git.
We normally commit to the repository many times an hour. If you ever need it, extensive documentation is available online. When anyone checks in changes, the CI system will check out a fresh copy of the application and run all the tests.
You can also set up your CI system so that your customers can use it to play with the bleeding-edge version of your application. For example, Dave originally wrote this chapter using Emacs because he thinks that its Filladapt mode is unsurpassed when it comes to neatly formatting XML as he types. Sam updated the chapter using Vim. But many think that neither Emacs nor Vim is ideal for Rails development. This is more than an aesthetic feature: having an editor indent your program as you type is the best way to spot bad nesting in your code.
Being able to reindent is important when you refactor your code and move stuff. You need an environment that helps you navigate quickly among these.
We prefer a combination of a tree view of files in a sidebar, a small set of keystrokes that help us find a file or files in a directory tree by name, and some built-in smarts that know how to navigate say between a controller action and the corresponding view. Names in Rails tend to be long.
A nice editor will let you type the first few characters and then suggest possible completions to you at the touch of a key. Indeed, many Rails developers use plain old editors. With other, less expressive languages, programmers rely on IDEs to do much of the grunt work for them, because IDEs do code generation, assist with navigation, and compile incrementally to give early warning of errors.
Spend a week or so trying alternatives before settling in. So, our main development desktop has an editor window and a browser window permanently open. We normally run this window with a small font so it takes up less space. If we see something interesting flash by, we increase the font size to investigate.
We also need access to the Rails API documentation, which we view in a browser. In the Introduction, we talked about using the gem server command to run a local web server containing the Rails documentation.
This is convenient, but it unfortunately splits the Rails documentation across a number of separate documentation trees. You may have to make minor adjustments to any explicit SQL in our code, but Rails pretty much eliminates database-specific SQL from applications.
This section contains links to instructions to get that done. The database drivers are all written in C and are primarily distributed in source form. For Linux, you need gcc and friends but these will likely already be installed.
You also need to install your database driver into the correct version of Ruby. Why do we need a tool to do this? Well, we could just hack. After all, a Rails application is just Ruby source code. But Rails also does a lot of magic behind the curtain to get our applications to work with a minimum of explicit configuration. To get this magic to work, Rails needs to find all the various components of your application.
The rails command creates this directory structure for us and populates it with some standard Rails code. In that directory, use the rails command to create an application called demo. Note: if you want to specify which Rails version to use, as described in Choosing a Rails Version, on page 14, now is the time to do so. Pop down into that directory and list its contents using ls on a Unix box or using dir on Windows. This command also detects common installation errors.
This command is a wrapper, or binstub, for the Rails executable. If you see a bunch of messages concerning already initialized constants or a possible conflict with an extension, consider deleting the demo directory, creating a separate RVM gemset,1 and starting over.
The localhost part of the address means that the Puma web server will only accept requests that originate from your machine. The result is shown in the screenshot on page If you look at the window where you started the server, you can see tracing showing that you started the application. When the time comes to shut down your application, you can press Ctrl-C in this window to stop the server.
If you want to enable this server to be accessed by other machines on your network, you will either need to list each server you want to have access 1. Hello, Rails! Rails accepts incoming requests from a browser, decodes the request to find a controller, and calls an action method in that controller. The controller then invokes a particular view to display the results to the user.
The good news is that Rails takes care of most of the internal plumbing that links all these actions. To write our Hello, World! This command is rails generate. You concentrate on creating the application, and Rails takes care of the details. Learn Rails the way the Rails core team recommends it, along with the tens of thousands of developers who have used this broad, far-reaching tutorial and reference.
We start with a step-by-step walkthrough of building a real application, and in-depth chapters look at the built-in Rails features.
Follow along with an extended tutorial as you write a web-based store application. Eliminate tedious configuration and housekeeping; internationalize your applications; incorporate Ajax, REST, web services, and e-mail handling into your applications; test your applications as you write them using the built-in testing frameworks, and deploy your applications easily and securely.
New in this edition is coverage of Action Cable and completely updated code for Rails 5. This book will take you through the steps to install Rails and its dependencies.
Test Driven Development in Ruby.
0コメント