Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1

56 | Chapter 2: ActiveSupport and RailTies


Finally, when we leave the debugger withcont(c), the request continues loading in
the web browser, and our debugger console becomes a server console again.


(rdb:1) c
Rendered /layouts/_nav (0.00012)
Rendered /layouts/_footer (0.00008)
Completed in 39.54861 (0 reqs/sec) | Rendering: 0.01811 (0%) | DB: 0.15506 (0%)
| 200 OK [http://localhost/signup/check_for_service]

Where to Start


Pick something interesting


Don’t discount the importance of finding something you like and running with it.
This approach has several advantages. It keeps you looking at aspects that interest
you, while taking you across the basic components, such as ActiveSupport, that you
will need to know. You will also pick up the idioms that other Rails programmers
use, and you will probably learn something new in the process.


Learn to love global search. Find an interesting method and search Rails for all of the
places that method is called.


Start at the top


The end of this chapter will explain how Rails initialization works. These functions
provide good entry points for studying the Rails source. You can start from
Initializerand trace a request down through a sequence of calls to your applica-
tion, following the same path that Ruby takes when executing your code.


Read the Tests


Rails has an extremely comprehensive set of tests. In fact, the tests are sometimes
more helpful than the official documentation, because the tests specify proper behav-
ior through code. The tests provide credible, proven examples of how to work with
the library in question. Since many of the tests are written in a Test-Driven Develop-
ment (test-first) style, they often provide more implementation details than the docu-
mentation does.


For example, this code from ActiveRecord’sbinary_test.rbproves that ActiveRecord
is binary-clean:


def setup
Binary.connection.execute 'DELETE FROM binaries'
@data = File.read(BINARY_FIXTURE_PATH).freeze
end

#...
Free download pdf