- •Introduction
- •Rails Is Agile
- •Finding Your Way Around
- •Acknowledgments
- •Getting Started
- •Models, Views, and Controllers
- •Installing Rails
- •Installing on Windows
- •Installing on Mac OS X
- •Installing on Unix/Linux
- •Rails and Databases
- •Keeping Up-to-Date
- •Rails and ISPs
- •Creating a New Application
- •Hello, Rails!
- •Linking Pages Together
- •What We Just Did
- •Building an Application
- •The Depot Application
- •Incremental Development
- •What Depot Does
- •Task A: Product Maintenance
- •Iteration A1: Get Something Running
- •Iteration A2: Add a Missing Column
- •Iteration A4: Prettier Listings
- •Task B: Catalog Display
- •Iteration B1: Create the Catalog Listing
- •Iteration B2: Add Page Decorations
- •Task C: Cart Creation
- •Sessions
- •More Tables, More Models
- •Iteration C1: Creating a Cart
- •Iteration C3: Finishing the Cart
- •Task D: Checkout!
- •Iteration D2: Show Cart Contents on Checkout
- •Task E: Shipping
- •Iteration E1: Basic Shipping
- •Task F: Administrivia
- •Iteration F1: Adding Users
- •Iteration F2: Logging In
- •Iteration F3: Limiting Access
- •Finishing Up
- •More Icing on the Cake
- •Task T: Testing
- •Tests Baked Right In
- •Testing Models
- •Testing Controllers
- •Using Mock Objects
- •Test-Driven Development
- •Running Tests with Rake
- •Performance Testing
- •The Rails Framework
- •Rails in Depth
- •Directory Structure
- •Naming Conventions
- •Active Support
- •Logging in Rails
- •Debugging Hints
- •Active Record Basics
- •Tables and Classes
- •Primary Keys and IDs
- •Connecting to the Database
- •Relationships between Tables
- •Transactions
- •More Active Record
- •Acts As
- •Aggregation
- •Single Table Inheritance
- •Validation
- •Callbacks
- •Advanced Attributes
- •Miscellany
- •Action Controller and Rails
- •Context and Dependencies
- •The Basics
- •Routing Requests
- •Action Methods
- •Caching, Part One
- •The Problem with GET Requests
- •Action View
- •Templates
- •Builder templates
- •RHTML Templates
- •Helpers
- •Formatting Helpers
- •Linking to Other Pages and Resources
- •Pagination
- •Form Helpers
- •Layouts and Components
- •Adding New Templating Systems
- •Introducing AJAX
- •The Rails Way
- •Advanced Techniques
- •Action Mailer
- •Sending E-mail
- •Receiving E-mail
- •Testing E-mail
- •Web Services on Rails
- •Dispatching Modes
- •Using Alternate Dispatching
- •Method Invocation Interception
- •Testing Web Services
- •Protocol Clients
- •Securing Your Rails Application
- •SQL Injection
- •Cross-Site Scripting (CSS/XSS)
- •Avoid Session Fixation Attacks
- •Creating Records Directly from Form Parameters
- •Knowing That It Works
- •Deployment and Scaling
- •Picking a Production Platform
- •A Trinity of Environments
- •Iterating in the Wild
- •Maintenance
- •Finding and Dealing with Bottlenecks
- •Case Studies: Rails Running Daily
- •Appendices
- •Introduction to Ruby
- •Ruby Names
- •Regular Expressions
- •Source Code
- •Cross-Reference of Code Samples
- •Resources
- •Index
|
|
CROSS-REFERENCE OF CODE SAMPLES |
512 |
|
def rails_root |
|
|
|
@rails_root ||= Pathname.new(RAILS_ROOT).cleanpath.to_s |
|
|
|
end |
|
|
|
end |
|
|
|
notifier/app/views/system_notifier/exception_notification.rhtml: |
|
|
File 153 |
<% require 'pp' -%> |
|
|
|
A <%= @exception.class %> occurred in |
|
|
|
<%= @controller.controller_name %>#<%= @controller.action_name %>: |
|
|
|
<%= @exception.message %> |
<%= @backtrace.first %> |
|
|
------------------------------- |
|
|
|
Request information: |
|
|
|
------------------------------- |
|
|
|
* URL: <%= @request.protocol %><%= @host %><%= @request.request_uri %> |
|
|
|
* Parameters: <%= @request.parameters.inspect %> |
|
|
|
* Rails root: <%= @rails_root %> |
|
|
|
------------------------------- |
|
|
|
Session dump: |
|
|
|
------------------------------- |
|
|
|
<% for variable in @request.session.instance_variables -%> |
|
|
|
<% next if variable =~ /^@db/ -%> |
|
|
|
* <%= variable %>: |
|
|
|
<%= PP.pp(@request.session.instance_variable_get(variable),""). |
|
|
|
gsub(/\n/, "\n |
").strip %> |
|
|
<% end -%> |
|
|
|
------------------------------- |
|
|
|
Environment: |
|
|
|
------------------------------- |
|
|
|
<% for key, value in @request.env -%> |
|
|
|
* <%= key %>: <%= value.to_s.strip %> |
|
|
|
<% end -%> |
|
|
|
------------------------------- |
|
|
|
Full execution backtrace: |
|
|
|
------------------------------- |
|
|
|
<%= @backtrace.join "\n |
" %> |
|
C.3 Cross-Reference of Code Samples
The following list can be used to find the file containing source code in the book. If a source sample has a marginal note containing a number, you can look that number up in the list that follows to determine the file containing that code. The files are available for download from http://pragmaticprogrammer.com/titles/rails.
1ar/acts_as_list.rb
2ar/acts_as_tree.rb
3ar/aggregation.rb
4ar/associations.rb
5ar/counters.rb
6ar/create.sql
7ar/dump_orders_table.rb
8ar/dump_serialize_table.rb
9ar/encrypt.rb
10ar/find_examples.rb
11ar/new_examples.rb
12ar/observer.rb
13ar/optimistic.rb
14ar/self_association.rb
15ar/sti.rb
16ar/transactions.rb
Prepared exclusively for Rida Al Barazi
Report erratum
CROSS-REFERENCE OF CODE SAMPLES |
513 |
17cookies/cookie1/app/controllers/content_controller.rb
18cookies/cookie1/app/controllers/cookies_controller.rb
19cookies/cookie1/app/controllers/session_controller.rb
20cookies/cookie1/app/sweepers/article_sweeper.rb
21cookies/cookie1/db/create.sql
22depot1/db/create.sql
23depot10/app/controllers/store_controller.rb
24depot10/app/views/layouts/store.rhtml
25depot10/app/views/store/display_cart.rhtml
26depot11/app/controllers/store_controller.rb
27depot11/app/helpers/application_helper.rb
28depot11/app/models/cart.rb
29depot11/app/views/store/display_cart.rhtml
30depot12/app/controllers/store_controller.rb
31depot12/app/models/line_item.rb
32depot12/app/models/order.rb
33depot12/app/views/admin/_form.rhtml
34depot12/app/views/admin/new.rhtml
35depot12/app/views/layouts/store.rhtml
36depot12/app/views/store/checkout.rhtml
37depot12/db/create.sql
38depot13/app/views/store/checkout.rhtml
39depot14/app/controllers/store_controller.rb
40depot14/app/views/store/checkout.rhtml
41depot15/app/views/store/checkout.rhtml
42depot15/app/views/store/display_cart.rhtml
43depot16/app/controllers/admin_controller.rb
44depot16/app/models/order.rb
45depot16/app/views/admin/_order_line.rhtml
46depot16/app/views/admin/ship.rhtml
47depot16/db/create.sql
48depot17/app/controllers/admin_controller.rb
49depot17/app/models/order.rb
50depot17/app/views/layouts/admin.rhtml
51depot18/app/controllers/application.rb
52depot18/app/controllers/login_controller.rb
53depot18/app/models/order.rb
54depot18/app/models/user.rb
55depot18/app/views/login/add_user.rhtml
56depot18/app/views/login/index.rhtml
57depot18/db/create.sql
58depot19/app/controllers/admin_controller.rb
59depot19/app/controllers/application.rb
60depot19/app/controllers/login_controller.rb
61depot19/app/models/user.rb
62depot19/app/views/layouts/admin.rhtml
63depot2/app/models/product.rb
64depot2/db/create.sql
65depot3/app/models/product.rb
66depot3/app/views/admin/list.rhtml
67depot4/app/views/admin/list.rhtml
68depot4/public/stylesheets/scaffold.css
69depot6/app/controllers/store_controller.rb
70depot6/app/models/product.rb
71depot6/app/views/store/index.rhtml
72depot7/app/views/layouts/store.rhtml
73depot7/app/views/store/index.rhtml
74depot8/app/controllers/application.rb
75depot8/app/controllers/store_controller.rb
76depot8/app/models/cart.rb
77depot8/app/models/line_item.rb
78depot8/app/views/store/display_cart.rhtml
79depot8/app/views/store/index.rhtml
80depot8/db/create.sql
81depot9/app/models/cart.rb
82depot9/app/views/store/display_cart.rhtml
83depot_final/app/controllers/admin_controller.rb
84depot_final/app/controllers/application.rb
85depot_final/app/controllers/login_controller.rb
Prepared exclusively for Rida Al Barazi
Report erratum
CROSS-REFERENCE OF CODE SAMPLES |
514 |
86depot_final/app/controllers/store_controller.rb
87depot_final/app/helpers/application_helper.rb
88depot_final/app/models/cart.rb
89depot_final/app/models/line_item.rb
90depot_final/app/models/order.rb
91depot_final/app/models/product.rb
92depot_final/app/models/user.rb
93depot_final/app/views/admin/_order_line.rhtml
94depot_final/app/views/admin/list.rhtml
95depot_final/app/views/admin/ship.rhtml
96depot_final/app/views/layouts/admin.rhtml
97depot_final/app/views/layouts/store.rhtml
98depot_final/app/views/login/add_user.rhtml
99depot_final/app/views/login/index.rhtml
100depot_final/app/views/login/list_users.rhtml
101depot_final/app/views/login/login.rhtml
102depot_final/app/views/store/checkout.rhtml
103depot_final/app/views/store/display_cart.rhtml
104depot_final/app/views/store/index.rhtml
105depot_final/config/database.yml
106depot_final/db/create.sql
107depot_final/public/stylesheets/admin.css
108depot_final/public/stylesheets/depot.css
109depot_testing/app/controllers/application.rb
110depot_testing/app/controllers/login_controller.rb
111depot_testing/app/models/product.rb
112depot_testing/test/fixtures/categories_products.yml
113depot_testing/test/fixtures/orders.yml
114depot_testing/test/fixtures/performance/orders.yml
115depot_testing/test/fixtures/products.yml
116depot_testing/test/fixtures/users.yml
117depot_testing/test/functional/login_controller_test.rb
118depot_testing/test/functional/search_controller_test.rb
119depot_testing/test/functional/store_controller_test.rb
120depot_testing/test/mocks/test/payment_gateway.rb
121depot_testing/test/performance/order_test.rb
122depot_testing/test/test_helper.rb
123depot_testing/test/unit/cart_test.rb
124depot_testing/test/unit/product_test.rb
125depot_testing/test/unit/product_txn_test.rb
126depot_ws/app/apis/backend_api_generated.rb
127depot_ws/app/apis/order_service.rb
128depot_ws/app/apis/product_api.rb
129depot_ws/app/apis/product_auth_api.rb
130depot_ws/app/apis/product_service.rb
131depot_ws/app/controllers/backend_auth_controller.rb
132depot_ws/app/controllers/backend_controller.rb
133depot_ws/app/controllers/backend_controller_generated.rb
134depot_ws/app/controllers/layered_backend_controller.rb
135depot_ws/test/functional/backend_api_test.rb
136erb/ex1.rhtml
137erb/ex2.rhtml
138erb/ex3.rhtml
139erb/ex4.rhtml
140filter/app/controllers/compress_controller.rb
141mailer/app/controllers/order_controller.rb
142mailer/app/controllers/test_controller.rb
143mailer/app/models/incoming_ticket_handler.rb
144mailer/app/models/order_mailer.rb
145mailer/app/views/order_mailer/_html_line_item.rhtml
146mailer/app/views/order_mailer/_line_item.rhtml
147mailer/app/views/order_mailer/confirm.rhtml
148mailer/app/views/order_mailer/sent.rhtml
149mailer/test/fixtures/orders.yml
150mailer/test/functional/order_controller_test.rb
151mailer/test/unit/order_mailer_test.rb
152notifier/app/models/system_notifier.rb
153notifier/app/views/system_notifier/exception_notification.rhtml
154routing/examples.rb
Prepared exclusively for Rida Al Barazi
Report erratum
CROSS-REFERENCE OF CODE SAMPLES |
515 |
155routing/examples2.rb
156routing/examples_named.rb
157views/app/controllers/application.rb
158views/app/controllers/array_controller.rb
159views/app/controllers/blog1_controller.rb
160views/app/controllers/blog2_controller.rb
161views/app/controllers/blog_controller.rb
162views/app/controllers/pager_controller.rb
163views/app/controllers/test_controller.rb
164views/app/controllers/upload_controller.rb
165views/app/helpers/test_helper.rb
166views/app/models/article.rb
167views/app/models/picture.rb
168views/app/views/array/edit.rhtml
169views/app/views/blog/index.rhtml
170views/app/views/blog/list.rhtml
171views/app/views/blog1/list.rhtml
172views/app/views/blog2/list.rhtml
173views/app/views/pager/user_list.rhtml
174views/app/views/partial/_animal.rhtml
175views/app/views/partial/_spacer.rhtml
176views/app/views/partial/list.rhtml
177views/app/views/test/calculate.rhtml
178views/app/views/test/select.rhtml
179views/app/views/upload/get.rhtml
180views/app/views/upload/show.rhtml
181views/components/sidebar/link/get_links.rhtml
182views/components/sidebar/link_controller.rb
183views/db/create.sql
184views/lib/eval_template.rb
185views/lib/rdoc_template.rb
186web2/app/controllers/example_controller.rb
187web2/app/controllers/guesswhat_controller.rb
188web2/app/controllers/list_controller.rb
189web2/app/controllers/list_no_ajax_controller.rb
190web2/app/models/item.rb
191web2/app/views/example/check.rhtml
192web2/app/views/example/compat.rhtml
193web2/app/views/example/compat_form.rhtml
194web2/app/views/example/effects.rhtml
195web2/app/views/example/effectswithoutajax.rhtml
196web2/app/views/example/index.rhtml
197web2/app/views/example/multiple.rhtml
198web2/app/views/example/observer.rhtml
199web2/app/views/example/periodic.rhtml
200web2/app/views/example/say_hello.rhtml
201web2/app/views/example/search.rhtml
202web2/app/views/example/update_many.rhtml
203web2/app/views/guesswhat/_form.rhtml
204web2/app/views/guesswhat/index.rhtml
205web2/app/views/layouts/list.rhtml
206web2/app/views/list/index.rhtml
207web2/app/views/list_no_ajax/_item.rhtml
208web2/app/views/list_no_ajax/index.rhtml
209work/demo1/app/controllers/say_controller.rb
210work/demo2/app/controllers/say_controller.rb
211work/demo3/app/views/say/hello.rhtml
212work/demo4/app/controllers/say_controller.rb
213work/demo4/app/views/say/hello.rhtml
214work/demo5/app/controllers/say_controller.rb
215work/demo5/app/views/say/goodbye.rhtml
216work/demo6/app/views/say/goodbye.rhtml
217work/demo6/app/views/say/hello.rhtml
218work/demo7/app/controllers/say_controller.rb
219work/demo7/app/views/say/goodbye.rhtml
220ws/dispatching_mode.rb
Prepared exclusively for Rida Al Barazi
Report erratum