`, 713
=~, 775
===, 764
accepts_nested_attributes_for, 362–365
classes 118
halting, 121
inline method, 118
skipping, 120
communication with view, 115
layouts, specifying, 111
postbacks, 381
standard RESTful actions, 69–73
verify method, 117
custom email headers, 495
generating URLs inside messages, 498
handing inbound attachments, 500–501
HTML messages, 496
multipart messages, 497
preparing outbound messages, 494–496
raising delivery errors, 21
sending, 499
server configuration, 502
customizing validation error output, 337–338
ERb. See ERb
filename conventions, 314
Haml. See Haml
Helpers. See Helpers
logging, 328
partial_counter variable, 328
partials. See Partials
rendering 327
AttributeMethods module, 625–627
Conversion module, 629
ForbiddenAttributesError, 635
SecurePassword, 638
testing compatibility of custom classes with Lint::Tests, 635
:counter cache option, 207–208
:counter sql option, 200
:dependent option, 201, 208, 235
:finder sql option, 200
AssociationProxy class, 239–240
belongs_to. See belongs_to associations
destroying records, 201
foreign-key constraints, 292
has_and_belongs_to_many. See has_and_belongs_to_many associations
has_many. See has_many associations
has_many :through. See has_many :through associations
indexing, 509
many-to-many relationships, 222–233
one-to-many relationships, 196–204
one-to-one relationships, 233–236
size of, 202
reloading, 142
typecasting, 142
Base class, 120
basic object operations, 138–151
concurrency. See Database locking
configuration, 171
legacy naming schemes, 133
magic timestamp columns, 186–187
sequencing, 174
pattern, 129
arel_table, 165
exists, 160
extending, 160
having, 161
joins, 162
none, 162
readonly, 163
references, 163
reverse_order, 164
select, 159
unique, 164
RecordInvalid exception, 252–253
RecordNotSaved exception, 200–201, 271
records
random ordering, 158
touching, 149
STI (Single-Table Inheritance), 280–287
conditional validation, 255–256
contexts, 256
enforcing uniqueness of join models, 250–251
testing with Shoulda, 262
active?, 170
acts_like?, 673–674, 682, 738, 750, 764
adapter_name, 170
add, 632
added?, 632
add_index, 179
add_on_blank, 632
add_on_empty, 632
after_add, 214
after_commit, 270
after_create, 270
after_destroy, 258, 262, 270, 274
after_fork, 539
after_initialize, 137, 269, 274–276
after_remove, 215
after_rollback, 270
after_save, 270
after_touch, 270
after_update, 270
after_validation, 269–270, 643
Unobtrusive JavaScript (UJS), 547–550
alias_method_chain, 529, 717–718
all_day, 765
all_month, 765
all_quarter, 765
all_week, 765
all_year, 765
allow_forgery_protection, 23
and_return, 593
anonymous?, 718
any?, 199
append, 656
arel_table, 165
around_create, 270
around_save, 270
Array.wrap, 657
as: association_name, 215
as_json, 632–633, 639, 659–660, 682, 687, 697
assert
assert_equal, 584
assert_no_difference, 762
assert_no_match, 759
assert_not, 762
assert_not_empty, 760
assert_not_equal, 760
assert_not_in_delta, 760
assert_not_in_epsilon, 760
assert_not_includes, 760
assert_not_instance_of, 760
assert_not_kind_of, 760
assert_not_nil, 760
assert_not_operator, 760
assert_not_predicate, 760
assert_not_respond_to, 760
assert_not_same, 760
assert_nothing_raised, 760
assert_raise, 761
Data URL, 571
built-in SASS asset path helpers, 570–571
getting the URL of an asset file, 570
images, 570
index files, 565
search path, 564
custom compressor, 569
JavaScripts, 568
stylesheets, 568
web server configuration, 572–573
Assets debug mode, 22
assigns, 318
associate_with, 688
Asynchronous processing. See Background processing.
at_beginning_of_day, 674, 683, 765
at_beginning_of_hour, 683, 765
at_beginning_of_minute, 683, 765
at_beginning_of_month, 674–675
at_beginning_of_quarter, 675, 766
at_beginning_of_week, 675, 766
at_beginning_of_year, 675, 766
Atom Feeds
autodetection, 338
attr_accessible, 481
attr_internal_accessor, 718–719
attr_internal_reader, 718
attr_internal_writer, 719
attr_protected, 481
attr_readonly, 150
attribute_method_affix, 626
attribute_method_prefix, 626
attribute_method_suffix, 626
attributes, 141
attributes=, 141
audio_path, 341
audio_tag, 341
authenticate_user!, 462
Authentication
Active Resource, 467
client-side certificates, 490
HTTP basic, 467
HTTP digest, 468
auto_discovery_link_tag, 338–339
autoclose, 446
autoload, 691
autoload_at, 692
autoload_module!, 689
autoload_once_paths, 687
autoload_under, 692
autoloadable_module?, 689
autoloaded?, 689
autoloads, 692
await, 673
background processing, 527–543
base_path, 318
be_an_error, 530
be_routable, 604
before_action, 116
before_destroy, 151, 216, 268–270, 273–274, 276
before_first_fork, 539
before_fork, 539
before_perform, 539
before_remove, 216
before_update, 270
begin_db_transaction, 167
beginning_of_*
beginning_of_day, 674, 683, 765
beginning_of_quarter, 675, 766
belongs_to associations, 149, 180, 196, 205–214
building and creating related objects, 206
polymorphic, 197
reloading, 205
touch, 210
benchmarking, 120, 213, 219, 221, 658–659
binary data storage, 185
blank?, 633, 657, 698, 704, 729, 730, 739, 749, 778
build_association, 206
Builder::XmlMarkup class, 617, 620–622
button_tag, 379
by, 510
byte / bytes, 731
cache, 510
cache_classes=, 18
cache_directory, 507
cache_if, 516
cache_key, 513, 517, 525, 637, 660
cache_path, 520
cache_store=, 452–453, 519–520, 522
cache_sweeper, 518
cache_unless, 516
Caching
avoiding extra database activity during, 518–519, 521–522
CacheHelper module, 347
conditional caching, 516
controlling web caches and proxies, 523–524
disabling in development mode, 20
logging, 519
new caches, 522
query caching, 145
calculate, 200
Callbacks
has_many associations, 214
capitalize, 725
CAS, 465
cattr_accessor, 670
cattr_reader, 671
cattr_writer, 671
change, 178, 584–585, 676, 684, 767
changed, 630
changed_attributes, 631
changed?, 630
changes, 631
check_box, 367
check_box_tag, 379
Class
class << self, 297
classify, 753
cleanup, 661
clear, 200, 261, 661, 689, 708
clear_query_cache, 145
clone, 739
collection_check_boxes, 373–374
collection_radio_buttons, 374–375
color_field, 367
color_field_tag, 379
column, 179
commit_db_transaction, 168
compact, 699
compact!, 699
compiler_class, 447
compose, 725
concat, 395
concerning, 719
Concurrency. See Database Locking
config, 673
config_accessor, 673
Configurable module, 673
configure, 673
consider_all_requests_local=, 20
console, 17
constant_watch_stack, 688
content_for?, 349
content_tag, 394
context, 578
Controllers. See Action Controller
Convention over configuration, 103, 129, 132, 171, 401
:secure option, 456
signing, 456
copy_instance_variables_from, 718
count_by_sql, 144
Country Select gem, 783
create_association, 206
create_join_table, 178
created_at, 186
created_on, 186
CRUD (Create Read Update Delete), 138–151
CSS
linking stylesheets to template, 340
relation to Haml, 446
sanitizing, 393
Currency
formatting, 385
current
current_cycle, 396
current_page, 419
current_page?, 419
cycle, 396
connecting to multiple, 165–166
foreign-key constraints, 292
pessimistic, 154
migrations. See ActiveRecord, Migrations.
date_field, 367
date_field_tag, 380
DATE_FORMATS hash constant, 770
date_select, 350
datetime
datetime_field_tag, 380
datetime_local_field, 368
datetime_local_field_tag, 380
day / days, 737
days_in_month, 767
Debugger gem, 783
Decent Exposure gem, 105, 317–318
decode, 712
decompose, 725
decrypt_and_verify, 715
deep_merge, 700
deep_merge!, 700
deep_stringify_keys, 702
deep_symbolize_keys, 702
deep_transform_keys, 702
default_locale, 402
default_scope, 266
default_timezone=, 171
define_attribute_method, 627
define_attribute_methods, 627
define_model_callbacks, 628–629
delay, 534
delay_for, 534
delay_unti, 534
delete, 168, 201, 271, 633, 662
delete_matched, 662
demodulize, 753
depend_on, 689
Deprecation, 21, 693–694, 722, 745
Deprecation.behavior, 693
descendants, 694
describe, 578
destroy_all, 201
destroyed?, 151
direct_descendants, 694
disconnect!, 170
distance_of_time_in_words, 355–356, 416
distance_of_time_in_words_to_now, 356
distinct, 222
does_not_match?, 588
dom_id, 426
Domain-Specific Languages, 131, 298
downcase, 726
drop_table, 192
each, 633
Eager load, 20
eager_autoload, 692
eager_load!, 692
element, 637
Email. See Action Mailer
email_field, 368
email_field_tag, 380
enable_warnings, 713
encode, 712
encode64, 779
encrypt_and_sign, 715
end_of_*
ends_with?, 757
Enumerable, extensions, 696–697
Devise, 463
Haml versus, 433–434, 439, 463. See also Haml
rendering inline template code, 106
escape_attrs, 447
escape_html, 447
escape_javascript, 385
escape_once, 394
exabyte / exabytes2, 731
except!, 701
exception_handler, 418
excerpt, 397
Excerpting text, 397
execute, 168
exists?, 160
expire
expires_in, 520
expires_now, 524
explicitly_unloadable_constants, 688
extract!, 703
extract_options!, 655
Facebook Open Graph meta tags, 316
fallbacks=, 25
favicon_link_tag, 339
favicon.ico file, 339
field_set_tag, 380
fifth, 652
file_field, 368
Files
extensions by Active Support, 698–699
reporting sizes to users, 385–389
find
find_tzinfo, 776
find_zone, 771
find_zone!, 772
Firebug, 546
flash.now, 321
flush, 759
font_path, 341
format, 447
formatted_offset, 685, 770, 776
accepts_nested_attributes_for method, 362–363
automatic view creation, 335–337
button_to helper method, 418, 548–549
fortnight / fortnights, 737
forty_two, 652
fourth, 652
freeze, 763
fresh_when, 525
from_json, 639
from_xml, 622–624, 640, 699–700
full_messages, 633
full_messages_for, 633
dependencies, 8
locking, 7
generate, 716
generated_attribute_method, 627
gigabyte / gigabytes, 731
grapheme_length, 726
grouped_collection_select, 372
Gzip, 705
boolean, 436
empty tags, 439
creating elements, 434
doctype, 440
interpolation, 442
multiline declarations, 443
handle_asynchronously, 529
has_and_belongs_to_many associations, 222–226
extra columns, 225
real join models and habtm, 225–226
has_key?, 634
has_many associations, 214–222
:conditions option, 251
:include option, 213
callbacks, 214
has_many :through associations, 226–230
usage, 228
:as, 235
:class name option, 235
:dependent, 235
options, 235
scopes, 236
together with has_many, 235
Hash.from_trusted_xml, 699
HashWithIndifferentAccess class, 705
Helper methods
helper specs, 605
writing your own View helpers, 422–425
hidden_field, 368
hidden_field_tag, 382
hide_action, 116
highlight, 397
history, 688
hook!, 689
hour / hours, 738
HTML
escaping, 442, 447, 485–486, 697–698
sanitizing, 487
tags
audio, 341
empty, 439
form. See Forms.
password, 383
script, 385
select, 383
video, 342
html_escape_once(s), 698
html_safe, 757
HTTP
stateless, 449
verbs (GET, POST, etc.), 68–71, 74, 419, 549
human_attribute_name, 413–414, 417, 641
human_name, 419
humanize, 754
hyphenate_data_attrs, 447
i18n_key, 637
i18n_scope, 641
image_submit_tag, 382
in?, 740
in_groups, 655
in_groups_of, 656
in_milliseconds, 738
in_time_zone, 682, 686, 758, 772
include, 202, 634, 740, 746–747
increment_counter, 271
indent, 752
indent!, 752
index, 179
index_by, 696
inflections, 709
inherited, 694
file parameter logging, 12
wrap parameters, 15
inquiry, 756
insert, 168
insert_after, 98
insert_before, 98
instance_values, 740
instance_variable_names, 740–741
Internationalization (I18n), 399–418
default locale, 11
i18n_key, 637
i18n_scope, 641
interpolation, 442
storing custom translations, 413–316
invalid?, 642
irregular, 709
is_utf8?, 757
it, 581
JavaScript
escaping, 385
postprocessing, 658
Unobtrusive JavaScript (UJS), 547–550
javascript_include_tag, 339–340, 559, 569
javascript_path, 340
javascript_tag, 385
joins, 162
jQuery framework, 547, 550, 552, 557–558. See also Turbolinks
:json, 107
PostgreSQL column type, 310–311
Redis database, 532
serializers, 639
strings, 659–660, 682, 687, 749, 763
variants, 126
wrap parameters, 15
json_escape, 698
keys, 634
kilobyte / kilobytes, 731
kind, 649
l, 401
label_tag, 382
last_month / prev_month, 678, 768
last_quarter / prev_quarter, 678, 768
last_year / prev_year, 678, 768
LDAP, 465
length, 202
let!, 580
link_to helper methods, 549–550
link_to_if, 420
link_to_unless, 420
link_to_unless_current, 420–421
list_of, 444
load, 742
load?, 689
load_file, 690
load_missing_constant, 690
load_once_path?, 690
loadable_constants_for_path, 690
loaded, 688
local, 776
local_constants, 722
local_to_utc, 776
lock!, 154
log_activity, 688
log_level, 16
logger, 321
backtrace silencing, 12–13, 657–658
colorization, 34
level override, 16
Syslog, 35
tagged, 32
lookup_ancestors, 641
lookup_store, 522
mail_to, 421
mark_for_unload, 690
mattr_accessor, 719
mattr_reader, 719
mattr_writer, 719
mechanism, 688
megabyte / megabytes, 731
Memcached, session store, 452–453
MessageEncryptor class, 715
MessageVerifier class, 715–716
method_missing, 726
middle_of_day / noon, 678, 684, 768
mime_type, 447
minute / minutes, 738
mock, 520
mock_model, 605
mock_with, 598
model_name, 638
month / months, 738
month_field, 369
month_field_tag, 382
ms, 658
multiline?, 747
multiple_of?, 712
mute, 664
MVC (Model-View-Controller), 2, 15, 37, 95, 106, 311
Named scopes. See Active Record, scopes
namespace, 59
Nested Form Fields gem, 785–786
new_constants_in, 690
next_*
Nonces, 454
none, 162
Notifications, 729
now, 777
nsec, 685
number_field, 369
number_to_currency, 385–386, 417
number_to_percentage, 388
number_with_delimiter, 389, 417
number_with_precision, 389–390, 417
Numbers
extensions to Numeric class, 738–743
object_id, 205
option_groups_from_collection_for_select, 372, 375–376
options, 664
options_from_collection_for_select, 378
ordinalize, 712
overlaps?, 747
page_class, 444
param_key, 637
params, 322
params hash, 322
parent, 722
parent_name, 722
parse, 777
parser_class, 447
rendering collections, 327–328
rendering objects, 327
reuse, 324
wrapping and generalizing, 425–426
password_field, 370
password_field_tag, 383
perform_caching=, 20, 22, 24, 509
period_for_local, 777
period_for_utf, 777
persisted?, 138, 302–303, 335, 629
petabyte / petabytes, 731
Pluralization
Inflector class, 12
pluralize_table_names=, 133
prepend, 657
prepend_before_filter, 118–119
presence, 739
present?, 739
preserve, 448
previous_changes, 631
primary_key_prefix_type=, 133
Prototype framework, 547
provide, 349
proxy_owner, 240
proxy_reflection, 240
proxy_target, 240
published_prior_to, 240
controller integration, 472
qualified_const_defined?, 690, 723
qualified_const_get, 723
qualified_const_set, 723
qualified_name_for, 691
quietly, 713
Rack::Sendfile middleware, 124
RACK_ENV variable, 1
routes as Rack endpoints, 48
radio_button, 370
radio_button_tag, 383
Railcasts, 790
Rails
class loader and reloading, 17, 615–619
development of, xl, xliii–xliv
lib directory, 20
root directory, 4
scaffolding, 147, 174, 333, 434
autoload_paths, 16, 687, 689–690, 692
boot.rb file, 9
cherry-picking frameworks used, 10
custom environments, 23
environment.rb file, 9, 502, 557, 599
generator defaults, 11
initializers. See Initializers
RAILS_ENV variable, 1
raise_delivery_errors=, 21, 25
Rake tasks
database-related, 171, 191–194
listing routes, 53
Rails log files, 30
Rspec Rails gem, 596
Spring application preloader, 17
Random ordering (of records), 157–158
range_field, 370
range_field_tag, 383
raw, 390
raw_connection, 170
read, 664
readonly_attributes, 150
reconnect!, 170
record_timestamps=, 187
RecordNotFound exception, 139
redefine_method, 724
redirect_to, 54
reference / references, 163, 180, 691
Regexp, extensions, 747
register, 14
register_alias, 14
register_javascript_expansion, 345–346
register_stylesheet_expansion, 345–346
release, 673
reload, 240
remove_constant, 691
remove_filters, 658
remove_index, 180
remove_possible_method, 724
remove_timestamps, 181
remove_unloadable_constants!, 691
remove_whitespace, 448
remove!, 751
rename, 181
another actions’s template, 93, 102–104
inline templates, 106
JSON, 107
nothing, 108
partials, see Partials.
render_views method, 603
text, 106
XML, 107
reorder_characters, 728
replace, 203
Request handling
in routing, 99
request, 322
require_dependency, 742
require_or_load, 689, 691, 742
Rescuable module, 748
rescue_from, 748
reset, 240
reset_callbacks, 668
reset_counters, 208
reset_cycle, 398
reset_sequence!, 168
respond_to, 322
REST and RESTful design, 63–93
controller-only resources, 83–86
forms, 359
resources and representations, 64–65
singular resource routes, 73
standard controller actions, 61–64
reverse, 726
reverse_merge, 703
reverse_merge!, 703
reverse_order, 164
reverse_update, 703
reversible, 175
revert, 181
rollback_db_transation, 168
route_key, 638
route_to, 604
:id field, 44
constraining by request method, 41
name_path versus name_url, 54–55
rack endpoints, 48
:format parameter, 86
controller mappings, 75
RPX authentication, 465
custom expectation matchers, 588–591
generator settings, 11
grouping related examples, 578
shared behaviors, 591
shared context, 592
spec_helper.rb file, 596–597, 607–608
Ruby
$LOAD PATH, 19
hashes, 375, 386, 450, 456, 657
Marshal API, 450
modules for reusing common behavior, 292–296
Ruby Toolbox, 789
RubyGems, xlvii
dependencies, 8
Git repository, loading directly from, 4–5
safe_join, 390
sanitize, 393
sanitize_css, 393
save, 147
scope, 57
Scopes. See Active Record, scopes
search_field, 370
search_field_tag, 383
search_for_file, 691
seconds_since_midnight, 684, 769
seconds_to_utc_offset, 777
seconds_until_end_of_day, 684, 769
secret_key_base, 27
Security
cross-site request forgery (XSRF), 360, 487–490
cross-site scripting (XSS), 483–484
model mass-assignment attributes protection, 481–483
secure sockets layer. See SSL
select, 159, 203–204, 213, 222, 372
select_all, 168
select_day, 352
select_hour, 352
select_tag, 383
select_time, 354
select_value, 169
select_values, 169
select_year, 354
serializable_hash, 639
serve_static_assets=, 22
cleaning old sessions, 450, 452, 455
RESTful storage considerations, 85
turning off sessions, 451
session, 322
set, 634
set_callback, 668
show_exceptions=, 22
delayed Action Mailer, 533–534
error handling, 536
scheduled jobs, 533
silence!, 665
silence_stream, 713
silence_warnings, 713
simple_format, 398
Simple Form gem, 788
singleton_class, 714
singular_route_key, 638
singularize, 755
site=, 204
skip_callback, 668
smtp_settings, 502
SOAP, 64
Specjour, 610
Spring application preloader, 17–18
squish, 751
certificates for asset hosts, 345
serving protected assets, 345
starts_with?, 757
store_full_sti_class=, 171
String
usage versus symbols, 141
stringify_keys, 702
StringInquirer class, 758
strip_heredoc, 757
strip_links, 393
strip_tags, 393
stylesheet_link_tag, 340
stylesheet_path, 340
subclasses, 671
submit, 370
submit_to_remote, 361
superclass_delegating_accessors, 671
supports_count_distinct?, 170
supports_migrations?, 170
suppress, 714
swapcase, 727
Symbol
extensions, 759
usage versus strings, 141
t, 401
table_name_prefix=, 133
table_name_suffix=, 133
tableize, 755
tables, 171
tagged, 759
telephone_field, 370
telephone_field_tag, 384
template_engine, 11
Templates. See View templates
terabyte / terabytes, 731
test_framework, 11
text_area_tag, 384
text_field, 371
text_field_tag, 384
third, 652
thread_variable?, 763
thread_variable_get, 763
thread_variable_set, 763
thread_variables, 763
Time
reporting distances in time, 355–356
storing in database, 185
Time Zones
default, 10
time
time_field, 371
time_field_tag, 384
time_select, 351
time_tag, 356
time_zone_options_for_select, 373, 378–379
time_zone_select, 373
timestamps, 181
titleize, 755
to_a, 634
to_constant_name, 691
to_default_s, 653
to_f, 685
to_formatted_s, 652–653, 659, 681, 686, 731–732, 746, 770–771
to_h, 758
to_hash, 634
to_i, 686
to_key, 629
to_model, 629
to_options, 702
to_partial_path, 629
to_sentence, 653
to_yaml, 779
toggle, 271
toggle!, 271
touch, 210
transform_keys, 703
translate, 401, 407–408, 410–412
travel, 762
travel_to, 762
ugly, 448
undefine_attribute_method, 627
underscore, 755
unhook!, 691
Unicode
multibiyte safe proxy for, 756
security concerns of, 392
unloadable, 743
Unobtrusive JavaScript (UJS), 547–550
helpers, 548
jQuery UJS custom events, 550
update_attribute, 148–149, 260–261
update_column(s), 260–261, 271
update_counters, 271
updated_at, 186
updated_on, 186
URL
generation, 43
patterns in routing, 42
url_field, 371
us_utf8?, 757
use_zone, 772
usec, 686
utc, 684
utc?, 684
utc_to_local, 778
valid?, 146, 241–242, 256, 635, 643
validate, 210–211, 218, 260, 649
validate!, 648
validates_absence_of, 242, 643
validates_acceptance_of, 242–243, 643
validates_confirmation_of, 244, 644
validates_exclusion_of, 246, 644
validates_format_of, 245–246, 645–646
validates_inclusion_of, 246, 645
validates_length_of, 246–247, 645–646
validates_numericality_of, 247–248, 646–647
validates_presence_of, 248–249, 647
validates_uniqueness_of, 249–251
Validation. See Active Record, validations
validators, 648
validators_on, 648
capturing block content, 395
concat method, 395s
cycling content, 398
encapsulating logic in helper methods, 423–424
highlighting content, 396
localization, 399
transforming text into HTML, 398
translation. See Internationalization.
word wrap, 399
See also Action View, 313–329
values, 635
verify!, 171
video_path, 342
warnings_on_first_load, 688
week / weeks, 738
week_field, 371
week_field_tag, 385
will_unload?, 691
with_indifferent_access, 701, 705
word_wrap, 399
Active Record associations, 614–617
extra elements, 618
overriding, 620
Ruby hashes, 616
typecasting, 624
y, 101
Devise, 460
Sidekiq, 535
year / years, 738
zone, 772
18.217.150.123