= (equal sign)
outputting results, 107–108
outputting strings, 108
sanitizing, 108
# (pound sign)
comment indicator, 103
in ID names, 106
/ (slash)
in file paths, 21
path expansion, 22
. (dot), in class names, 106
& (ampersand), anchors in YAML nodes, 115
== (equal signs), sanitizing, 108
- (hyphen), code indicator, 107
% (percent sign), tag indicator, 105
{} (curly braces), in Haml tags, 107
() (parentheses), in optional route matching, 52
<% %> ERB delimiters, 102
<% =%> ERB delimiters, 102
<%= %> ERB delimiters, 102
<%= -%> ERB delimiters, 102
~ (tilde), preserving whitespace, 108
absolute_url
method, 71
Abstract controllers, 69–70
abstract!
method, 229, 238–239
abstract?
method, 229
AbstractController
class, methods
before
, 69
absolute_url
, 71
action_name
, 70
action_name=
, 70
add_filter
, 69
after
, 69
body
, 71
body=
, 71
capture
, 71
capture_erb
, 71
catch_content
, 71
clear_content
, 71
concat
, 71
concat_erb
, 71
content_type
, 71
content_type=
, 71
controller_name
, 69–70
default_layout
, 70
filter, 69
inherited
, 69
instance, 70
layout
, 70
normalize_filters!
, 69
partial
, 71
relative_url
, 71
render, 70
render
, 71
render_all
, 71
render_html
, 71
render_js
, 71
render_json
, 71
render_options
, 70
render_text
, 71
render_xml
, 71
render_yaml
, 71
skip_after
, 69
skip_before
, 69
skip_filter
, 69
subclasses_list
, 69
throw_content
, 71
throw_content?
, 71
URL, 71
url
, 71
view, 71
Access privileges, properties, 131
Access realms, 240
:accessor
option, 131
Action caching, 274–275
action
key, 42
action_name
method, 70
action_name=
method, 70
Actions
callable, returning, 72
callable, setting, 79
calling, 66
mailers
invoking, 258–259
naming, 257–258
methods available as, 68
names, 70
parts, 266–267
readability, improving, 78
ActionStore
strategy store, 270
ActiveRecord, definition, 26
ActiveRecord associations, versus DataMapper, 132–133
Adapter options, Rack, 23–25
Adapters, DataMapper, 114
add_filter
method, 69
Adding
controller names to subclasses_list
, 69
CSS error class, 186
filters to filter chains, 69
names to routes, 57–58
query parameters, 143
routes, 44–45
session functionality, 29
add_rakefiles
plugin, 222
Addressable URIs, storing as strings, 155
add_reversed
query parameter, 145
add_slice
method, 202–203
AdhocStore
strategy store, 270
after
class method, 81–82
After filter chain, 69
After filters, 81–82
after
method
AbstractController
class, 69
authentication strategies, 229
creating hooks, 154
filter method, 69
Strategy
class, 229
after_app_loads
blocks, 30
AfterAppLoads
boot loader, 30
after_app_loads
method, 13–14
after_authentication
method, 237
after_callbacks
array, 237
Aggregates, 158–161
all
method, 142–145
alter_table_column_statement
method, 126
Ampersand (&), anchors in YAML nodes, 115
app
argument, 3
app/
directory, 9
Application controllers, 72–74
Application layouts
alternative, specifying, 28–29
core, 3
custom, 3
overview, 2–3
very flat, 2–6
Applications
creating, 1–2
development environment, 7, 16–17
nontemplate code, loading, 29
production environment, 7, 16–17
reloading, 11
single file. See Flat application layouts; Very flat application layouts.
assert_kind
method, 144
belongs to, 132–135
belongs_to
method, 132–135
cardinality, specifying, 136
DataMapper versus ActiveRecord, 132–133
has
method, 132–133
has through, 138–139
join table models, creating, 139
ManyToMany
associations, 139
many-to-many-through, 139
one-to-many-through, 138–139
overview, 132–133
symbolized class names, 136
through
method, 138–139
Attaching files to email, 260–261
Attributes, updating, 152–153
attribute_set
method, 152
Audit routes rake task, 48
audit:routes
command, 48
auth
core. See Authentication, auth
core.
auth more
. See Authentication, auth more
.
auth
password slices. See Authentication, auth
password slices.
authenticate
method, 235
authenticate!
method, 225–226
abstract!
method, 229
abstract?
method, 229
add_rakefiles
plugin, 222
after
method, 229
after_authentication
method, 237
after_callbacks
array, 237
authenticate
method, 235
authenticate!
method, 225–226
Authentication
class, 223–227
before
method, 229
before_app_loads
plugin, 222
callbacks, 236–237
customizations, 236
customize_default
method, 236
ensure_authenticated
helper, 234–235
error messages, storing, 232–233
halt!
method, 230
halted?
method, 230
helpers, 234–235
hooking methods, 224
inherited
method, 229
initialize
method, 230
model class, selecting, 223
push_path
method, 222
redirect
method, 230
responses, 233–234
responses.rb
file, 233–234
router helper, 235
run_after_authentication_callbacks
method, 226–227, 237
serial callbacks, 226–227
sessions, 231
setup.rb
file, 222
strategies.rb
file, 222
Strategy
class, 227–231
user_class
method, 231
controller, 245
encrypt
method, 243
models, 242–245
overview, 237–238
passwords, encrypting, 243–244
redirect_back_or
method, 245
redirecting logins, 245
strategies
abstract!
method, 238–239
access realms, 240
Base
class, 238
basic, 239–241
basic_authentication?
method, 240
login_param
method, 239
OpenID, 242
password form, 241
password_param
method, 239
run!
method, 239
Authentication, auth
password slices
controller, 247–249
destroy
action, 248
error_messages_for
method, 250
Exceptions
controller, 247–249
lib
files, 246–247
login view, 249–250
Sessions
controller, 247–249
underscored filters, 248
update
action, 248
views, 249–250
Authentication
class, 223–227
Auto-increment, enabling, 131
Auto-incrementing integers, 155
Automatic
form actions, setting, 187
parameters, routing match rules, 51
parameters, symbolic matching, 51
auto_migrate!
method, 123–126
auto_upgrade!
method, 123–126
:auto_validation
option, 132
Average value, calculating, 159
avg
method, 159
Base
class, 238
basic_authentication?
method, 240
BCryptHash
property type, 155
be_client_error
matcher, 291–292
before
class method, 80–81
Before filter chain, 69
Before filters, 80–81
before
method
AbstractController
class, 69
authentication strategies, 229
creating hooks, 154
Strategy
class, 229
BeforeAppHooks
boot loader, 29
before_app_loads
blocks, 29
before_app_loads
plugin, 222
Belongs-to associations, 132–135
be_missing
matcher, 291–292
be_successful
matcher, 291–292
BigDecimal
class, 128
Binary flags, storing as integers, 155
Blank, testing for, 22
blank?
method, 22
Block-aware enhancer, 103–105
BlockAwareEnhancer
, 103–105
Blocks
calling later, 97
placing in worker queue, 74
body
method, 71
body=
method, 71
Body of controller response, getting/setting, 71
Boolean
class, 128. See also TrueClass
.
Boolean property type, 128
Boot loaders, overview, 27
BootLoader
class
AfterAppLoads
, 30
BeforeAppHooks
, 29
BuildFramework
, 28–29
ChooseAdapter
, 31
Cookies
, 30
Defaults
, 28
Dependencies
, 29
DropPidFile
, 28
LoadClasses
, 29
Logger
, 27
MimeTypes
, 30
MixinSession
, 29
RackUpApplication
, 31–32
ReloadClasses
, 32
ReloadTemplates
, 32
SetupSession
, 30
SetupStubClasses
, 31
StartWorkerThread
, 31
Templates
, 29–30
Bound variants versus unbound, 181
bound_check_box
method, 182–183
Builder
module, 179
BuildFramework
boot loader, 28–29
build_request
method, 275–277
build_url
method, 275–277
cache
action, 274–275
cache!
action, 274–275
cache_action
action, 274–275
Caching
configuring
ActionStore
, 270
AdhocStore
, 270
FileStore
, 269–270
fundamental stores, 269–270
GzipStore
, 270
MemcachedStore
, 269–270
PageStore
, 270
SHA1Store
, 270
strategy stores, 270
delete
method, 273
deleting, 273
exists?
method, 272
fetch
methods, 273
fetching, 273
helpers
action caching, 274–275
build_request
method, 275–277
build_url
method, 275–277
cache
action, 274–275
cache!
action, 274–275
cache_action
action, 274–275
eager caching, 275–277
eager_cache
method, 275–277
fetch_fragment
method, 277
fetch_partial
method, 277–278
fragment caching, 277
partial caching, 277–278
read
method, 272
reading, 272
writable?
method, 271–272
write
method, 271–272
writing, 271–272
Caitlin, Hampton, 105
callable_actions
method, 72
Callbacks, authentication, 236–237
Camel case, converting strings to, 21
camel_case
method, 21
capture
method, 71
capture_erb
method, 71
Cardinality, specifying, 136
Casting values, 128–129
catch_content
method, 71
cattr_accessor
method, 20
cattr_reader
method, 20
cattr_writer
method, 20
-C
flag, 9–10
Checkbox control, 182–183
check_box
method, 189–190
Checking routes, 45
check_request_for_route
method, 11
ChooseAdapter
boot loader, 31
Classes
listing, 20
models
creating, 116
inheritance, 116
organizing, 115
Principle of Substitutability, 116
required for DataMapper, 115–117
Resource
method, 115–117
names
Haml views, 106–107
storing as strings, 128
reloading, 32
class_inheritable_accessor
method, 20
class_inheritable_reader
method, 20
class_inheritable_writer
method, 20
class_provided_formats
method, 72–73
class_provided_formats=
method, 72–73
clear!
method, 208
clear_content
method, 71
Clearing content, rendering templates, 71
clear_provides
method, 72
Client response time, filters, 82
close_sandbox!
method, 11
Collections, reversing object order, 145
Comments, ERB views, 103
Compiling templates, 89–90
concat
method, 71
concat_erb
method, 71
Conditions, validations, 163–164
conditions
query parameter, 145
config/
directory, 12
Config
method, 14
Configuration
caching
ActionStore
, 270
AdhocStore
, 270
FileStore
, 269–270
fundamental stores, 269–270
GzipStore
, 270
MemcachedStore
, 269–270
PageStore
, 270
SHA1Store
, 270
strategy stores, 270
mailers
delivery methods, 254–255
quota checking, 255
sendmail, 254
SMTP, 253–254
test_send
method, 254
sessions, 206
Configuration files
databases, 19–20
database.yml
, 19–20
development.rb
, 16
environments, 16–17
init script
after_app_loads
method, 13–14
basic configuration, 14
dependencies, 13–14
gems and load path, 12
inflector customization, 15
libraries, distributing, 12–13
ORM options, 14–15
plugins, distributing, 12–13
RubyGems, 12–13
template engines, 14
testing options, 15
init.rb
, 19–20
logging
debug messages, 18
error messages, 18
example, 18
fatal messages, 18
info messages, 18
log file location, 17
message levels, specifying, 18
viewing logs, 18
warn messages, 18
production.rb
, 16–17
router, 17
routers, 43
test.rb
, 17
YAML files, 19–20
Console methods, 10–11
Console traps, 9–10
Constants, converting to paths, 21
Content type for controller response, getting/setting, 71
content_type
method, 71
content_type=
method, 71
Contexts, validations, 164
Controller access, sessions, 220
class methods
callable_actions
, 72
class_provided_formats
, 72
class_provided_formats=
, 72
clear_provides
, 72
does_not_provide
, 72
format, 72
general, 72
hide_action
, 72
only_provides
, 72
overview, 70
provides
, 72
reset_provides
, 72
show_action
, 72
instance methods
class_provided_formats
, 73
class_provided_formats=
, 73
cookies
, 73
delete_cookie
, 73
does_not_provide
, 73
escape_xml
, 74
escaping, 74
format, 73
general, 73
h
, 74
headers
, 73
html_escape
, 74
nginx_send_file
, 74
only_provides
, 73
other, 74
params
, 73
provides
, 73
rack_response
, 73
redirect
, 73
render_chunked
, 74
render_deferred
, 74
render_then_call
, 74
request
, 73
run_later
, 74
send_chunk
, 74
send_data
, 74
send_file
, 74
session, 73
session
, 73
set_cookie
, 73
status
, 73
status=
, 73
stream_file
, 74
Controller classes
AbstractController
, methods
before
, 69
absolute_url
, 71
action_name
, 70
action_name=
, 70
add_filter
, 69
after
, 69
body
, 71
body=
, 71
capture
, 71
capture_erb
, 71
catch_content
, 71
clear_content
, 71
concat
, 71
concat_erb
, 71
content_type
, 71
content_type=
, 71
controller_name
, 69–70
default_layout
, 70
filter, 69
inherited
, 69
instance, 70
layout
, 70
normalize_filters!
, 69
partial
, 71
relative_url
, 71
render, 70
render
, 71
render_all
, 71
render_html
, 71
render_js
, 71
render_json
, 71
render_options
, 70
render_text
, 71
render_xml
, 71
render_yaml
, 71
skip_after
, 69
skip_before
, 69
skip_filter
, 69
subclasses_list
, 69
throw_content
, 71
throw_content?
, 71
URL, 71
url
, 71
view, 71
Application
, 72
Controller
, class methods
callable_actions
, 72
class_provided_formats
, 72
class_provided_formats=
, 72
clear_provides
, 72
does_not_provide
, 72
format, 72
general, 72
hide_action
, 72
only_provides
, 72
overview, 70
provides
, 72
reset_provides
, 72
show_action
, 72
Controller
, instance methods
class_provided_formats
, 73
class_provided_formats=
, 73
cookies
, 73
delete_cookie
, 73
does_not_provide
, 73
escape_xml
, 74
escaping, 74
format, 73
general, 73
h
, 74
headers
, 73
html_escape
, 74
nginx_send_file
, 74
only_provides
, 73
other, 74
params
, 73
provides
, 73
rack_response
, 73
redirect
, 73
render_chunked
, 74
render_deferred
, 74
render_then_call
, 74
request
, 73
run_later
, 74
send_chunk
, 74
send_data
, 74
send_file
, 74
session, 73
session
, 73
set_cookie
, 73
status
, 73
status=
, 73
stream_file
, 74
Controller classes, custom
actions
callable, setting, 79
hiding/showing, 79
readability, improving, 78
controller location, 75–76
naming controllers, 76
organizing methods
action readability, improving, 78
making methods available to subclasses, 77–78
overview, 76
sharing nonaction methods, 77
controller
key, 42
Controller prefixes, 59
Controller response
body, getting/setting, 71
content type, getting/setting, 71
controller_for_slice
method, 201
controller_name
method, 69–70
Controller#part
method, 266–267
Controllers
abstract, 69–70. See also AbstractController
.
application, 72–74
authentication
auth more
, 245
auth
password slices, 247–249
calling actions, 66
definition, 34
dispatching requests, 66–67
initializing, 66–67
location, 75–76
mailers, 257–258
Merb, 70–72. See also Controller
class.
names
adding to subclasses_list
, 69
creating, 76
returning, 69–70
parts, 263–266
rack response, 73
for slices, 200–201
Controller#send_mail
method, 258–259
Convention over configuration, 5
Converting
constants to paths, 21
numbers to currency values, 169–170
strings to camel case, 21
time to EpochTime, 155
Cookies
deleting, 73
functionality, loading, 30
getting, 73
session domain, setting, 206
session storage, 211–214
session store, encrypting, 206
setting, 73
Cookies
boot loader, 30
cookies
method, 73
CookieSession
class, 211–214
Core application layouts, 3
core
argument, 3
count
method, 159–161
Counting numerical properties, 159–161
coverage
task, 282
create
action, 62
create_model_storage
method, 123–126
create_table_statement
method, 127
CRUD (create, retrieve, update, delete) basics
all
method, 142–145
assert_kind
method, 144
creating records, 140–142
deleting collections, 154
deleting records, 154
destroy!:
method, 154
destroy
method, 154
enforcing types, 144
first
method, 142–145
lazy loading of collections, 146–148
lazy loading of properties, 148–150
LazyArray
class, 147–148
model objects, creating and saving, 140–142
N+1 queries, 150
overview, 140
query object algebra, 144
query parameters, adding, 143
Query#merge
method, 144–145
Relationship
class, 151–152
retrieving records
data sets, reloading, 146
fields, fetching as an array, 145
grouping by fields, 146
including other data, 145
lazy loading of collections, 146–148
limiting number returned, 146
links in related model data, 146
overview, 142–145
query offset, 146
query order, 146
reversing object order, 145
SQL conditions, setting, 145
strategic eager loading, 150–152
scoped_query
method, 143
special query parameters, 145–146
strategic eager loading, 150–152
updating records
attribute_set
method, 152
original values versus dirty values, 153
overview, 152
save
method, 152
update_attributes
method, 152–153
update_speed
method, 153
CSS error class, adding, 186
Csv
property type, 155
Curly braces ({}), in Haml tags, 107
Currency values, converting numbers to, 169–170
current_form_context
method, 187–188
Custom application layouts, 3
Customizations, authentication, 236
customize_default
method, 236
Cycle helpers, 176–177
cycle
method, 176–177
Cycling through a list of values, 176–177
Data sets, reloading, 146
Database storage
automigrating DB schema, 121–127
default configuration file, 120
overview, 120–121
sample_development.db
file, 120
Databases
accessing without a password, 19
configuration files, 19–20
creating with rake
, 120
database.yml
files, 19–20, 115
DataMapper
adapters, 114
associations, versus ActiveRecord, 132–133
CRUD. See CRUD (create, retrieve, update, delete) basics.
data sources, 114
database back ends, 114
definition, 26
Ferret adapter, 114
required module, 115–117
Salesforce adapter, 114
session storage, 217–219
Date and time. See also Helpers, date and time.
converting time to EpochTime, 155
property type, 128
time equivalent of date, 22
Date
class, 128
date
format, 171
DateAndTimeFormatting
module, 173
db
format, 171
Debug messages, logging, 18
Debugging code. See Interactive sessions.
Decimal places, setting, 132
Decimal precision, property type, 128
default
method, 57
:default
option, 131
default_cookie_domain
setting, 206
default_layout
method, 70
Defaults
boot loader, 28
Deferred blocks, running, 31
deferred
method, 82
Deferred routes, routing match rules, 53–54
Deferring rendering responses, 74
Defining property types, 127–130, 155–156
Delete button, creating, 191
DELETE verb, 39–40
delete_button
method, 191
delete_cookie
method, 73
Deleting
cache data, 273
collections, 154
cookies, 73
records, 154
URLs, 11
users, 62
Dependencies
gems as, 13–14
init script file, 13–14
loading, 29
models, 114
Dependencies
boot loader, 29
dependencies
method, 14
dependency
method, 13
Design principles, 5
destroy!:
method, 154
destroy
method, 154
destroy_model_storage
method, 123–126
Development environment, applications, 7, 16–17
development.rb
files, 16
Dirty values
versus original, 153
tracking properties for, 132
Discriminator
class, 128
_dispatch
method, 66
Dispatcher, overview, 33
Dispatching requests, 11, 66–67
dispatch_request
method, 11
dispatch_to
method, 11
display
method, 95–96
dm-aggregate
plugin, 158–161
dm-timestamps
gem, 156–158
does_not_provide
method, 72–73
Domain matching, 41
Dot (.), in class names, 106
DropPidFile
boot loader, 28
drop_table_statement
method, 126
Dual-formatted email messages, 255
Eager caching, 275–277
eager_cache
method, 275–277
Ebb adapter, 25
ebb
key, 25
edit
action, 62
-e
flag, 16
Email. See Mailers.
emongrel
key, 25
encrypt
method, 243
Encryption
cookies session store, 206
encrypt
method, 243
passwords, 243–244
strings, 155
Enforcing types, 144
ensure_authenticated
helper, 234–235
Enum
property type, 155
Enumerated values, storing as integers, 155
Environment configuration file, loading, 29
Environments
configuration files, 16–17
settings, 16–17
specifying, 16–17
EpochTime, converting to, 155
EpochTime
property type, 155
Equal sign (=)
outputting results, 107–108
outputting strings, 108
sanitizing, 108
Equal signs (==), sanitizing, 108
ERB format, rendering templates, 89
ERB (eRuby) views. See also Views.
# (pound sign), comment indicator, 103
<% %> delimiters, 102
<% =%> delimiters, 102
<%= %> delimiters, 102
<%= -%> delimiters, 102
basic delimiters, 102
block-aware enhancer, 103–105
BlockAwareEnhancer
, 103–105
comments, 103
overview, 101–102
whitespace, removing, 102
Error messages
logging, 18
storing, 232–233
error_messages_for
method, 186, 191, 250
escape_regex
method, 21
escape_xml
method, 74
Escaping
HTML entities, 74
methods, 74
strings, 155
XML entities, 74
Evented Mongrel adapter, 25
Exception controllers, setting up, 31
Exceptions
in controller code, 74, 87–88. See also Exceptions controller.
overview, 87
raising, 87
Exceptions
controller, 247–249
exists?
method, 272
Expiration time for sessions, setting, 206
Extlib. See also Stack.
/ (slash), in file paths, 21
/ (slash), path expansion, 22
blank, testing for, 22
blank?
method, 22
camel_case
method, 21
cattr_accessor
method, 20
cattr_reader
method, 20
cattr_writer
method, 20
class, 20
Class
class, 20
classes, listing, 20
class_inheritable_accessor
method, 20
class_inheritable_reader
method, 20
class_inheritable_writer
method, 20
date, 22
date, time equivalent, 22
DateTime
class, 22
escape_regex
method, 21
Hook
module, 23
in?
method, 21
inheritable class-level variables, creating, 20
keys, strings or symbols as, 22
lazy loading, 23
LazyArray
class, 23
Logger
class, 22
logging, 22
Mash
class, 22
meta_class
method, 21
methods, associating before/after other methods, 23
Object
class, 21
objects
in arrays, duplicating, 21
in arrays, finding, 21
singleton class access, 21
ObjectSpace
class, 20
overview, 20
Pathname
class, 22
Pooling
module, 23
resource sharing, 23
SimpleSet
class, 23
snake_case
method, 21
String
class, 21
strings
camel case, converting to, 21
escaping special characters, 21
as inline templates, 23
joining in file paths, 21
language translation, 21
path/constant conversion, 21
snake case, converting to, 21
String.translate
method, 21
String.translations
method, 21
t
method, 21
time, returning, 22
Time
class, 22
to_const_path
method, 21
to_const_string
method, 21
to_datetime
method, 22
to_json
method, 22
to_time
method, 22
try_dup
method, 21
unescape_regex
method, 21
unified class and instance variables, creating, 20
VirtualFile
class, 23
fake_request
method, 11
FalseClass
method, 22
FastCGI adapter, 25
Fatal messages, logging, 18
fcgi
key, 25
Ferret adapter, 114
fetch
methods, 273
fetch_fragment
method, 277
Fetching cache data, 273
fetch_partial
method, 277–278
-f
flag, 18
:field
option, 131
Fields
fetching as an array, 145
grouping retrieved data by, 146
names, overriding, 131
fields
query parameter, 145
Fieldset elements, creating, 180–182
fieldset_for
method, 189
fields_for
method, 189
File paths, strings in, 21
file_field
method, 189–190
FilePath
property type, 155
Files, attaching to email, 260–261
FileStore cache
store, 269–270
Filter chains, adding filters, 69
Filter methods, 69
Filters
before, 80–81
AbstractController
methods, 69
adding to a filter chain, 69
after, 81–82
after
class method, 81–82
after filter chain, 69
applying selectively, 82–83
before
class method, 80–81
client response time, 82
deferred
method, 82
ensuring option values are arrays, 69
before filter chain, 69
Haml views, 109
:if
option, 83
options, 82–83
overview, 79–80
passing parameters to, 83
skip_after
class method, 83–84
skip_before
class method, 83–84
underscored, 248
:unless
option, 83
:with
option, 83
finalize
method
SessionContainer
class, 208
SessionStoreContainer
class, 211
first
method, 142–145
Fixatable routes, 59–60
Flag
property type, 155
Flat application layouts, 3, 6–8
flat
argument, 3
Flexible segmentation, 52
Float
class, 128
Floating property type, 128
flush
method, 18
Form
module, 187–191
format
key, 42
:format
key, 163
Format methods, 72–73
:format
option, 132
date and time, 171–173
rendering templates
default, 89
ERB, 89
specifying, 92–94
form_contexts
method, 187–188
form_for
method, 188–189
actions, setting automatically, 187
context, changing from another form, 189
default builder, 187
elements, creating, 180–182, 185–187. See also Helpers, form.
helpers. See Helpers, form.
names, 188–189
without model object content, 188
ForumSlice
module, 196
Fragment caching, 277
Freezing gems, 13
Garbage collection, session storage, 215–216
Gems
as dependencies, 13–14
directory size, reducing, 13
freezing, 13
libraries, distributing, 12–13
and load path, init script file, 12
--no-rdoc
flag, 13
plugins, distributing, 12–13
RubyGems, 12–13
version-specific, installing, 13
generate
method
SessionContainer
class, 208
SessionStoreContainer
class, 211
get
method, 11
GET verb, 39–40
Getter/setter methods, dynamic creation, 119
Getting. See Retrieving; specific items.
Globs, 29
GzipStore
strategy store, 270
h
method, 74
halt!
method, 230
halted?
method, 230
:haml
parameter, 14
Haml views. See also Views.
= (equal sign)
outputting results, 107–108
outputting strings, 108
sanitizing, 108
. (dot), in class names, 106
== (equal signs), sanitizing, 108
- (hyphen), code indicator, 107
% (percent sign), tag indicator, 105
# (pound sign), in ID names, 106
{} (curly braces), in Haml tags, 107
~ (tilde), preserving whitespace, 108
class names, 106–107
filters, 109
history of, 105
HTML injections, preventing, 108
HTML-sensitive characters, sanitizing, 108
ID names, 106–107
indentation, 106
versus inline styles, 109
interpreting lines, 107
nesting code, 106
outputting lines, 107–108
sanitized lines, 108
tags, 105–106
whitespace, preserving, 108
Has associations, 132–133, 135–137
has
method, 132–133
Has through associations, 138–139
have_body
matcher, 292
have_content_type
matcher, 292
Headers, requests, 73
headers
method, 73
authentication, 234–235
caching
action caching, 274–275
build_request
method, 275–277
build_url
method, 275–277
cache
action, 274–275
cache!
action, 274–275
cache_action
action, 274–275
eager caching, 275–277
eager_cache
method, 275–277
fetch_fragment
method, 277
fetch_partial
method, 277–278
fragment caching, 277
partial caching, 277–278
cycle, 176–177
cycle
method, 176–177
date and time
date
format, 171
DateAndTimeFormatting
module, 173
db
format, 171
formats, 171–173
long
format, 171
prettier_time
method, 175–176
relative date and time, 175–176
relative time, 175–176
relative_date
method, 175
relative_date_span
method, 175
relative_time_span
method, 175
RFC 822 format, matching, 171
rfc822
format, 171
short
format, 171
Time DSL, 173–175
time
format, 171
time_lost_in_words
method, 175
numeric
minutes_to_hours
method, 169
to_currency
method, 169–170
two-digits
method, 168
ordinalize
method, 173
ordinals, 173
overview, 167
tag, 177–178
tag
method, 178
truncate
method, 167–168
Helpers, form. See also Forms.
builders
bound variants versus unbound, 181
bound_check_box
method, 182–183
Builder
module, 179
checkbox control, 182–183
CSS error class, adding, 186
error_messages_for
method, 186
fieldset elements, 180–182
fieldset
method, 180
form actions, setting automatically, 187
form elements, 180–182, 185–187
form
method, 180
forms, default builder, 187
label elements, 184–185
label
method, 184–185
name
parameter, 179
obj
parameter, 179
origin
parameter, 179
process_form_attrs
method, 180, 187
ResourcefulFormWithErrors
, 187
update_bound_check_box
method, 183–184
update_bound_controls
method, 186
update_*_controls
method, 181–182
validation errors, outputting, 186
helpers
check_box
method, 189–190
current_form_context
method, 187–188
delete button, creating, 191
delete_button
method, 191
error_messages_for
method, 191
fieldset
method, 189
fieldset_for
method, 189
fields_for
method, 189
file_field
method, 189–190
form context, changing from another form, 189
form
method, 188
Form
module, 187–191
form names, 188–189
form_contexts
method, 187–188
form_for
method, 188–189
forms without model object content, 188
hidden_field
method, 189–190
password_field
method, 189–190
radio_button
method, 189–190
radio_group
method, 189–190
select
method, 189–190
singleton form context, 188
text_area
method, 189–190
text_field
method, 189–190
validation errors, outputting, 191
overview, 179
hidden_field
method, 189–190
hide_action
method, 72
Hiding actions, 72
Hijacking user accounts, 59–60
Hook
module, 23
Hooking methods, authentication, 224
Hooks, models, 154
HTML (HyperText Markup Language)
email messages, 255
entities, escaping, 74
injections, preventing, 108
MIME set, rendering views with, 71
html
task, 282
html_escape
method, 74
HTML-sensitive characters, sanitizing, 108
HTTP verbs, 39–40
Hyphen (-), code indicator, 107
ID names, Haml views, 106–107
identify
method, 63
:if
option, 83
in?
method, 21
includes
query parameter, 145
Indentation, Haml views, 106
index
action, 61
:index
option, 132
Indexing properties, 132
Inflector customization, 15
info messages, logging, 18
Inheritable class-level variables, creating, 20
Inheritance, model classes, 116
inherited
method
AbstractController
class, 69
Strategy
class, 229
Init file, loading, 29
Init script file
after_app_loads
method, 13–14
basic configuration, 14
dependencies, 13–14
gems and load path, 12
inflector customization, 15
libraries, distributing, 12–13
ORM options, 14–15
plugins, distributing, 12–13
RubyGems, 12–13
template engines, 14
testing options, 15
initialize
method, 230
Initializing controllers, 66–67
init.rb
files, 19–20
Inline styles versus Haml views, 109
Inlining templates, 90
Instance methods, 70
Integer
class, 128
Integers. See also Numbers.
auto-incrementing, 155
binary flags as, 155
enumerated values as, 155
property type, 128
Interactive Merb, registering routes, 45–48
check_request_for_route
method, 11
close_sandbox!
method, 11
console methods, 10–11
console traps, 9–10
delete
method, 11
dispatch_request
method, 11
dispatch_to
method, 11
fake_request
method, 11
get
method, 11
logger output, flushing, 11, 18
open_sandbox!
method, 11
post
method, 11
put
method, 11
reload!
method, 11
reloading the application, 11
request
method, 11
request routes, checking or listing, 11
requests, 11
sandboxing, 11–12
show_routes
method, 11
starting, 9
trace_log!
method, 11
url
method, 11
URLs, 11
IP addresses, storing as strings, 155
IPAddress
property type, 155
IRB adapter, 25
irb
key, 25
Iterating through a list of values, 176–177
Join table models, creating, 139
JS MIME set, rendering views with, 71
JSON, storing as a string, 155
JSON MIME set, rendering views with, 71
Json
property type, 155
Kernel
methods, 293–294
:key
option, 131
Keys
action
, 42
controller
, 42
ebb
, 25
emongrel
, 25
fcgi
, 25
format
, 42
:format
, 163
irb
, 25
:key
option, 131
:length
, 163
:nullable
, 163
Rack, 25
route parameters, 42
runner
, 25
session_id_key
setting, 206
session_secret_key
setting, 206
:set
, 163
:size
, 163
strings or symbols as, 22
swift
, 25
table keys, defining, 131
thin
, 25
webrick
, 25
Label elements, creating, 184–185
label
method, 184–185
Language translation, 21
layout
method, 70
Layout options, rendering templates
class-level, setting, 70
disabling, 70
resetting, 70
setting, 70
Layout templates, 94–95
layout_for_slice
method, 201
Lazy loading
collections, 146–148
enabling, 131
:lazy
option, 131
properties, 148–150
:lazy
option, 131
:length
key, 163
:length
option, 131. See also :size
option.
lib
files, 246–247
Libraries, distributing, 12–13
limit
query parameter, 146
links
query parameter, 146
Listing
classes, 20
routes
with audit routes rake task, 48
audit:routes
command, 48
with interactive Merb, 45–48
route
command, 45
subclasses, 69
users, 61
Literal matching, routing match rules, 50–51
Literal segments, 40–41
LoadClasses
boot loader, 29
Location, controllers, 75–76
Logger
boot loader, 27
Logger
class, 22
Logger output, flushing, 11, 18
Loggers, updating, 29
Logging
configuration files
debug messages, 18
error messages, 18
example, 18
fatal messages, 18
info messages, 18
log file location, 17
message levels, specifying, 18
viewing logs, 18
warn messages, 18
Extlib, 22
Login view, 249–250
login_param
method, 239
Logins, redirecting, 245
long
format, 171
MailController
classes, 257–258
MailController#attach
method, 260–261
configuring, 253–255
MailFactory interface, 255–257
actions
invoking, 258–259
naming, 257–258
attaching files, 260–261
configuration
delivery methods, 254–255
quota checking, 255
sendmail, 254
SMTP, 253–254
test_send
method, 254
controllers, 257–258
Controller#send_mail
method, 258–259
dual-formatted messages, 255
generating mailer files, 261–262
HTML email, 255
MailController
classes, 257–258
MailController#attach
method, 260–261
MailFactory, 255–257
multipart messages, 255
parameters, 259–260
rendering message views, 261
templates, 261
testing, 261
:test_method
method, 261
using directly, 255–257
MailFactory, 255–257
ManyToMany
associations, 139
Many-to-many-through associations, 139
Mash
class, 22
Master process, 2
Match captures, registering routes with, 56
match
method, routing match rules, 50
Match rules. See Routing, match rules.
max
method, 159
Maximum value, calculating, 159
Memcached session storage, 216–217
MemcachedStore
cache store, 269–270
Memory session storage, 214–216
MemorySessionStore
class, 215–216
Merb controllers, 70–72
overview, 32–33
shutting down, 2
Merb stack. See Stack.
merb-gen
command, 1–2
meta_class
method, 21
(Method) parameters, 43
Method route conditions, 39–40
Methods. See also Helpers; specific methods.
associating before/after other methods, 23
available as actions, 68
organizing
action readability, improving, 78
making methods available to subclasses, 77–78
overview, 76
sharing nonaction methods, 77
MIME types, registering defaults, 30
MimeTypes
boot loader, 30
min
method, 159
Minimum value, calculating, 159
minutes_to_hours
method, 169
MixinSession
boot loader, 29
Model class, selecting for authentication, 223
Model objects, creating/saving, 140–142
Model serial IDs, property type, 128
Model specs, in testing, 283–285
model
task, 281
Models
after
method, 154
associations. See Associations.
authentication, auth more
, 242–245
creating, 116
inheritance, 116
organizing, 115
Principle of Substitutability, 116
required for DataMapper, 115–117
Resource
method, 115–117
configuration, 113–115
CRUD basics. See CRUD (create, retrieve, update, delete) basics.
database.yml
file, 115
DataMapper
adapters, 114
data sources, 114
database back ends, 114
dependencies, 114
hooks, 154
before
method, 154
plugins. See Plugins.
properties. See Properties.
repository configuration, 114–115
serial IDs, 128
YAML configuration file, 114–115
YAML nodes, 115
Mongrel adapter, 25
Multipart email messages, 255
N+1 queries, 150
name
method, 58
name
parameter, 179
Names
actions, 70
controllers
adding to subclasses_list
, 69
creating, 76
returning, 69–70
mail controller actions, 257–258
MailController
classes, 257
routes
adding, 57–58
controller prefixes, 59
namespaces, 59
prefixing, 58–59
namespace
method, 59
Namespaces, 59
Neighman, Daniel, 221
Nesting match statements, 50
new
action, 62
nginx_send_file
method, 74
NilClass
class, 22
Nontemplate code, loading, 29
--no-rdoc
flag, 13
normalize_filters!
method, 69
Null values, disallowing, 131
:nullable
key, 163
:nullable
option, 131
Numbers. See also Integers.
average value, calculating, 159
Boolean, 128
converting to currency, 169–170
counting, 159–161
dates and times, 128
decimal, precision, 128
decimal places, setting, 132
floating, 128
integers, 128
maximum value, calculating, 159
minimum value, calculating, 159
model serial IDs, 128
ordinals, 173
property types, 128
single-digit, padding to two digits, 168
summing, 159
Numeric
class, 22
Numeric helpers
minutes_to_hours
method, 169
to_currency
method, 169–170
two-digits
method, 168
obj
parameter, 179
Object
class
blank?
method, 22
in Extlib, 21
property type, 128
Objects
in arrays, duplicating, 21
in arrays, finding, 21
marshaling into records, 128
singleton class access, 21
ObjectSpace
class, 20
offset
query parameter, 146
One-to-many-through associations, 138–139
only_provides
method, 72–73
OpenID, authentication strategy, 242
open_sandbox!
method, 11
Optional matching, routing match rules, 52–53
options
method, 59
order
query parameter, 146
ordinalize
method, 173
Ordinals, 173
origin
parameter, 179
ORM options, init script file, 14–15
ORMs (object relational mappings), 25–27
PageStore
strategy store, 270
Parameters
mailers, 259–260
(Method) parameters, 43
passing to filters, 83
request parameters, 43
from requests, 73
route parameters, 43
params
method, 73
Parentheses (()), in optional route matching, 52
PartController
class, 263–266
Partial caching, 277–278
partial
method, 71
Partials, 111–112
actions, 266–267
controllers, 263–266
generating files, 267
Passing in literal strings, routing match rules, 51
Password form, authentication strategy, 241
password_field
method, 189–190
password_param
method, 239
Passwords. See also Authentication, auth
password slices; Security.
accessing databases without, 19
authentication. See Authentication, auth
password slices.
encrypting, 243–244
encryption, 243–244
form authentication strategy, 241
password_field
method, 189–190
password_param
method, 239
Path route conditions
definition, 39
literal segments, 40–41
overview, 40–41
query strings, 40
segments, 40–41
symbolic segments, 40–41
syntax, 40–41
Pathname
class, 22
Paths
converting to constants, 21
storing as strings, 155
Percent sign (%), tag indicator, 105
Persistent accessors, 118
Pidfile, dropping, 28
addressable URIs, storing as strings, 155
aggregates, 158–161
auto-incrementing integers, 155
average value, calculating, 159
avg
method, 159
binary flags, storing as integers, 155
count
method, 159–161
counting numerical properties, 159–161
distributing, 12–13
dm-aggregate
plugin, 158–161
dm-timestamps
gem, 156–158
encrypting strings, 155
enumerated values, storing as integers, 155
EpochTime, converting to, 155
escaping strings, 155
IP addresses, storing as strings, 155
JSON, storing as a string, 155
max
method, 159
maximum value, calculating, 159
min
method, 159
minimum value, calculating, 159
numerical properties, 159
parsing strings as CSVs, 155
paths, storing as strings, 155
property types, 155–156. See also specific types.
records, counting, 158–161
regular expressions, storing as strings, 155
strings, 155
sum
method, 159
summing numerical values, 159
timestamps, 156–158
URLs, strings in, 155
UUIDs, storing as strings, 155
validations. See also specific validation methods.
automatic, turning off, 132, 163
with blocks, 162
conditions, 163–164
confirming attributes, 162
contexts, 164
errors, 164–165
format of a value, 162
formats, 163
with methods, 162
numerical length, 162–163
numerical values, 162
overview, 162–163
presence of, 163
presence of a value, 162
within a range of values, 162–163
true values, 162
uniqueness, 162–163
validates_within
method, 163
YAML, storing as a string, 155
Pooling
module, 23
post
method, 11
POST verb, 39–40
Posting URLs, 11
Pound sign (#)
comment indicator, 103
in ID names, 106
Power, David, 255
:precision
option, 132
Prefixing route names, 58–59
Prepare block, router configuration, 43–44
prettier_time
method, 175–176
Principle of least surprise, 5
Principle of Substitutability, 116
process_form_attrs
method, 180, 187
Production environment, applications, 7, 16–17
production.rb
files, 16–17
access privileges, setting, 131
alter_table_column_statement
method, 126
auto-increment, enabling, 131
auto_migrate!
method, 123–126
auto_upgrade!
method, 123–126
create_model_storage
method, 123–126
create_table_statement
method, 127
database storage
automigrating DB schema, 121–127
default configuration file, 120
overview, 120–121
sample_development.db
file, 120
in DataMapper, benefits of, 121
decimal places, setting, 132
default value, setting, 131
defining
casting values, 128–129
options, 131–132. See also specific options.
overview, 127
property types, 127–130, 155–156. See also specific types.
destroy_model_storage
method, 123–126
drop_table_statement
method, 126
field names, overriding, 131
getter/setter methods, dynamic creation, 119
including in model files, 121
indexing, 132
lazy-loading, enabling, 131
null values, disallowing, 131
overview, 118–120
persistent accessors, 118
properties_with_subclasses
method, 127
property_schema_statement
method, 127
size, setting, 131
with subclasses, 127
table keys, defining, 131
tracking for dirtiness, 132
type plugins, 155–156
upgrade_model_storage
method, 123–126
validation, 132
values, setting with instance variables, 119–120
properties_with_subclasses
method, 127
property_schema_statement
method, 127
Protocol matching, 41
provides
method, 72–73
public/
directory, 9
push_path
method, 222
put
method, 11
PUT verb, 39–40
Putting URLs, 11
Queries
N+1, 150
parameters, adding, 143
special query parameters, 145–146
strings, path route conditions, 40
Query object algebra, 144
Query offset, 146
Query order, 146
Query#merge
method, 144–145
Quota checking, email, 255
Rack. See also Stack.
adapter options, 23–25
adapters, choosing, 31
Ebb adapter, 25
ebb
key, 25
emongrel
key, 25
Evented Mongrel adapter, 25
FastCGI adapter, 25
fcgi
key, 25
functional description, 24–26
IRB adapter, 25
irb
key, 25
Mongrel adapter, 25
ORMs (object relational mappings), 25
overview, 23
Runner adapter, 25
runner
key, 25
setting up, 31–32
swift
key, 25
Swiftiplied Mongrel adapter, 25
Thin adapter, 25
thin
key, 25
WEBrick adapter, 25
webrick
key, 25
Rack response, controllers, 73
rack_response
method, 73
RackUpApplication
boot loader, 31–32
radio_button
method, 189–190
radio_group
method, 189–190
Rake tasks, in testing, 279–282
read
method, 272
:reader
option, 131
Reading cache data, 272
Reaping session storage, 215–216
Records, counting, 158–161
redirect
matcher, 292
redirect
method
Controller
class, 73
registering a redirect, 56
Strategy
class, 230
redirect_back_or
method, 245
Redirecting logins, 245
Redirects
after-POST requests, 85
a caveat, 84–85
in before filters, 86–87
overview, 84
registering, 56
registering routes with, 56
redirect_to
matcher, 292
regenerate
method
SessionContainer
class, 208
SessionStoreContainer
class, 211
Regexp
property type, 155
generating slices, 195–196
registering routes with, 55–56. See also To
method; With
method.
Registering route parameters, 54
Registering routes with
match captures, 56
to
method, 54–55. See also Register
method; With
method.
with
method, 55. See also Register
method; To
method.
redirecting, 56
register
method, 55–56. See also To
method; With
method.
symbols, 56–57
Regular expressions
routing match rules, 53
segment-specific, routing match rules, 52
setting route conditions, 39
storing as strings, 155
validation against, 132
Relationship
class, 151–152
Relative time, 175–176
relative_date
method, 175
relative_date_span
method, 175
relative_time_span
method, 175
relative_url
method, 71
reload!
method, 11
reload
query parameter, 146
ReloadClasses
boot loader, 32
Reloading
applications, 11
classes, 32
ReloadTemplates
boot loader, 32
Renaming resources, 63
AbstractController
class, 71
basic rendering, 91–92
Render methods, 70
render_all
method, 71
render_deferred
method, 74, 96–97
render_html
method, 71
Rendering
email message views, 261
responses, 74
views, 71
basic rendering, 91–92
clearing content, 71
compiling templates, 89–90
display
method, 95–96
formats
default, 89
ERB, 89
specifying, 92–94
inlining templates, 90
layout options, 70
layout template, 94–95
overview, 89
render
method, 91–92
render methods, 70
render_chunked
method, 96
render_deferred
method, 96–97
render_then_call
method, 97
status code, setting, 94
:status
option, 94
render_js
method, 71
render_json
method, 71
render_options
method, 70
render_text
method, 71
render_then_call
method, 74, 97
render_xml
method, 71
render_yaml
method, 71
Repository configuration, 114–115
Request access, sessions, 219
Request
class, 33
Request helper, in testing, 289–290
Request matchers, in testing, 290–292
Request parameters, 43
Request routes, checking or listing, 11
Request specs, in testing, 285–288
request
task, 281
REQUEST_METHOD
option, 66–67
REQUEST_PATH
option, 66–67
Requests
building, 11
headers, 73
incoming, dispatching, 33
object routed to the controller, 73
overview, 33
parameters, 73
returning, 11
status codes, 73
reset_provides
method, 72
Resource
method, 115–117
resource
method, 62–63
Resource routes. See also Routers; Routes; Routing.
renaming resources, 63
standard resources routing
create
action, 62
deleting users, 62
destroy
action, 62
edit
action, 62
index
action, 61
new
action, 62
resources
method, 60–62
show
action, 62
single resource routing, 62–63
update
action, 62
updating users, 62
user accounts, creating, 62
user profiles, displaying, 62
users, listing, 61
Resource sharing, 23
ResourcefulFormWithErrors
, 187
resources
method, 60–62
respond_successfully
matcher, 291–292
Responses, authentication, 233–234
responses.rb
file, 233–234
Restarting after code changes, avoiding, 7
retrieve
method, 211
records
data sets, reloading, 146
fields, fetching as an array, 145
grouping by fields, 146
including other data, 145
lazy loading of collections, 146–148
limiting number returned, 146
links in related model data, 146
overview, 142–145
query offset, 146
query order, 146
reversing object order, 145
SQL conditions, setting, 145
strategic eager loading, 150–152
URLs, 11
RFC 822 format, matching, 171
rfc822
format, 171
route
command, 45
Route conditions
DELETE, 39–40
domain matching, 41
GET, 39–40
HTTP verbs, 40
methods, 39–40
minimal requirements, 39
paths
definition, 39
literal segments, 40–41
overview, 40–41
query strings, 40
segments, 40–41
symbolic segments, 40–41
syntax, 40–41
POST, 39–40
protocol matching, 41
PUT, 39–40
setting with regular expressions, 39
Route parameters
action
key, 42
controller
key, 42
defaults, setting, 57
definition, 42
format
key, 42
keys, 42
registering, 54
settings, 54
Router helper, authentication, 235
router.rb
files, 17
behaviors, definition, 38
configuration
configuration file, 43
prepare block, 43–44
route order, 44
router.rb
file, 43
routes, adding, 44–45
configuration files, 17
definition, 33
testing URL generation and recognition, 49–50
Routes
absolute URLs, returning, 71
adding, 44–45
checking, 45
definition, 38
fixatable, 59–60
including session IDs. See Session fixation.
interaction with resources. See Resource routes.
listing
with audit routes rake task, 48
audit:routes
command, 48
with interactive Merb, 45–48
route
command, 45
show_routes
method, 47–48
names
adding, 57–58
controller prefixes, 59
namespaces, 59
prefixing, 58–59
order, specifying, 44
registering with
match captures, 56
to
method, 54–55. See also Register
method; With
method.
with
method, 55. See also Register
method; To
method.
redirecting, 56
register
method, 55–56. See also To
method; With
method.
symbols, 56–57
relative URLs, returning, 71
session fixation, 59–60
deferred routes, 53–54
full regular expressions, 53
literal matching, 50–51
match
method, 50
nesting match statements, 50
overview, 50
passing in literal strings, 51
symbolic matching
() (parentheses), in optional matching, 52
automatic parameters, 51
flexible segmentation, 52
optional matching, 52–53
overview, 51
segment-specific regular expressions, 52
Routing, overview, 38
RSpec extensions, in testing, 292–294
RubyGems, 12–13
run!
method, 239
run_after_authentication_callbacks
method, 226–227, 237
run_later
method, 97
Runner adapter, 25
runner
key, 25
Salesforce adapter, 114
sample_development.db
file, 120
Sandboxing, 11–12
Sanitized lines, Haml views, 108
save
method, 152
:scale
option, 132
Schaefer, Bernerd, 114
scoped_query
method, 143
Security. See also Passwords.
hijacking user accounts, 59–60
session fixation, 59–60
Segments, path route conditions, 40–41
Segment-specific regular expressions, routing match rules, 52
select
method, 189–190
send_chunk
method, 74
send_data
method, 74
send_file
method, 74
Sending
binary data, 74
chunks, 74
files
attached to email, 260–261
overview, 97–98
send_file
method, 98
through nginx, 74
Sendmail, 254
Sequel, 26
Serial callbacks, authentication, 226–227
Serial
class, 128
Serial IDs, models, 128
:serial
option, 131
Serial
property type, 155
Server. See Merb servers.
Session containers, 207–208, 214–215
Session fixation, 59–60
Session methods, 73
Session store, accessing, 73
SessionContainer
class, 207–208
session_expiry
setting, 206
session_id=
method, 208
session_id_key
setting, 206
Sessions
authentication, 231
configuration, 206
containers, setting up, 30
controller access, 220
cookie domain, setting, 206
cookie session store, encrypting, 206
default values, setting up, 30
default_cookie_domain
setting, 206
definition, 34
expiration time, setting, 206
functionality, adding, 29
IDs, 205–206
overview, 205–206
request access, 219
session
method, 220
session_expiry
setting, 206
session_id_key
setting, 206
session_secret_key
setting, 206
session_store
setting, 206
clear!
method, 208
finalize
method
SessionContainer
class, 208
SessionStoreContainer
class, 211
generate
method
SessionContainer
class, 208
SessionStoreContainer
class, 211
regenerate
method
SessionContainer
class, 208
SessionStoreContainer
class, 211
retrieve
method, 211
session containers, 207–208, 214–215
SessionContainer
class, 207–208
session_id=
method, 208
SessionStoreContainer
class, 208–211
setup
method
SessionContainer
class, 208
SessionStoreContainer
class, 211
storage mechanisms
cookie sessions, 211–214
CookieSession
class, 211–214
DataMapper sessions, 217–219
garbage collection, 215–216
memcached sessions, 216–217
memory sessions, 214–216
MemorySessionStore
class, 215–216
reaping sessions, 215–216
TamperedWithCookie
error, 214
store containers, 208–211, 214–215
Sessions
controller, 247–249
session_secret_key
setting, 206
session_store
setting, 206
SessionStoreContainer
class, 208–211
:set
key, 163
set_cookie
method, 73
Setting. See specific items.
SessionContainer
class, 208
SessionStoreContainer
class, 211
setup.rb
file, 222
SetupSession
boot loader, 30
SetupStubClasses
boot loader, 31
SHA1Store
strategy store, 270
short
format, 171
show
action, 62
show_action
method, 72
Showing
actions, 72
SimpleSet
class, 23
Single resource routing, 62–63
Singleton form context, 188
Singular words, switching to plural, 15
:size
key, 163
Size of properties, setting, 131
:size
option, 131. See also :length
option.
skip_after
class method, 83–84
skip_after
method, 69
skip_before
class method, 83–84
skip_before
method, 69
skip_filter
method, 69
Slash (/)
in file paths, 21
path expansion, 22
slice
command, 196–199
slice
method, 201–203
Slices. See also Authentication, auth
password slices.
developing
building slices into gems, 199–200
controller_for_slice
method, 201
controllers, 200–201
ForumSlice
module, 196
generating slices, 193–196
layout_for_slice
method, 201
register
method, 195–196
running slices, 196–199
slice
command, 196–199
using
add_slice
method, 202–203
overview, 201
slice
method, 201–203
Slug
property type, 155
SMTP, 253–254
Snake case, converting strings to, 21
snake_case
method, 21
Spec files, in testing, 282–283
Special characters, escaping, 21
spectasks.rb
file, 279–280
SQL conditions, setting, 145
Stack. See also Extlib; Rack.
ORMs (object relational mappings), 26–27. See also ActiveRecord; Sequel.
plugins, 26–27
Standard application layouts, 3, 8–9
Standard resources routing
create
action, 62
deleting users, 62
destroy
action, 62
edit
action, 62
index
action, 61
new
action, 62
resources
method, 60–62
show
action, 62
single resource routing, 62–63
update
action, 62
updating users, 62
user accounts, creating, 62
user profiles, displaying, 62
users, listing, 61
StartWorkerThread
boot loader, 31
rendering templates, setting, 94
requests, sending, 73
in testing, 291–292
status
method, 73
status=
method, 73
:status
option, 94
Stepping through a list of values, 176–177
Storage mechanisms
cookie sessions, 211–214
CookieSession
class, 211–214
DataMapper sessions, 217–219
garbage collection, 215–216
memcached sessions, 216–217
memory sessions, 214–216
MemorySessionStore
class, 215–216
reaping sessions, 215–216
TamperedWithCookie
error, 214
Store containers, 208–211, 214–215
Storing sessions. See Sessions, storing.
Strategic eager loading, 150–152
strategies.rb
file, 222
Strategy
class, 227–231
Strategy stores, 270
stream_file
method, 74
Strings
camel case, converting to, 21
encrypting, 155
escaping special characters, 21, 155
globs, 29
as inline templates, 23
joining in file paths, 21
language translation, 21
parsing as CSVs, 155
path/constant conversion, 21
snake case, converting to, 21
storing, 128
truncating, 167–168
in URLs, 155
String.translate
method, 21
String.translations
method, 21
Stub classes, setting up, 31
Subclasses, listing, 69
subclasses_list
method, 69
sum
method, 159
Summing numerical properties, 159
swift
key, 25
Swiftiplied Mongrel adapter, 25
Symbolic matching
routing match rules
() (parentheses), in optional matching, 52
automatic parameters, 51
flexible segmentation, 52
optional matching, 52–53
overview, 51
segment-specific regular expressions, 52
Symbolic segments, 40–41
Symbolized class names, 136
Symbols
registering routes with, 56–57
thrown content, catching, 71
t
method, 21
Table keys, defining, 131
Tag helpers, 177–178
tag
method, 178
Tags, Haml views, 105–106
TamperedWithCookie
error, 214
Template engines, init script file, 14
template_roots=
method, 70, 71
Templates. See also Views.
capture
method, calling, 71
capturing ERB blocks, 71
concat
method, calling, 71
concatenating ERB blocks, 71
embedding in templates, 71
ERB blocks, 71
inline, strings as, 23
inlining, 29–30
mailers, 261
Merb view templates, 109–111
reloading, 32
rendering. See Rendering, templates.
within templates, 111–112
templating system, default, 101–102
throwing content, 71
thrown content, checking for, 71
view. See Flat application layouts.
Templates
boot loader, 29–30
Testing
be_client_error
matcher, 291–292
be_missing
matcher, 291–292
be_successful
matcher, 291–292
coverage
task, 282
extensions, 293–294
have_body
matcher, 292
have_content_type
matcher, 292
html
task, 282
Kernel
methods, 293–294
mailers, 261
model specs, 283–285
model
task, 281
rake tasks, 279–282
redirect
matcher, 292
redirect_to
matcher, 292
request helper, 289–290
request matchers, 290–292
request specs, 285–288
request
task, 281
respond_successfully
matcher, 291–292
routers, URL generation and recognition, 49–50
RSpec extensions, 292–294
spec files, 282–283
spectasks.rb
file, 279–280
status codes, 291–292
Testing environment, applications, 7, 16–17
Testing options, init script file, 15
:test_method
method, 261
test.rb
files, 17
test_send
method, 254
Text
class, 128
Text data, storing, 128
Text MIME set, rendering views with, 71
text_area
method, 189–190
text_field
method, 189–190
Thin adapter, 25
thin
key, 25
through
method, 138–139
throw_content
method, 71
throw_content?
method, 71
Tilde (~), preserving whitespace, 108
Time, returning, 22
Time DSL, 173–175
time
format, 171
time_lost_in_words
method, 175
Timestamps, 156–158
to
method, registering routes with, 54–55. See also Register
method; With
method.
to_const_path
method, 21
to_const_string
method, 21
to_currency
method, 169–170
to_datetime
method, 22
to_json
method, 22
to_time
method, 22
trace_log!
method, 11
:track
option, 132
TrueClass
class, 128. See also Boolean
class.
truncate
method, 167–168
try_dup
method, 21
two-digits
method, 168
Underscored filters, 248
unescape_regex
method, 21
Unified class and instance variables, creating, 20
Uniform Resource Locators (URLs). See URLs (Uniform Resource Locators).
unique
query parameter, 146
:unique_index
option, 132
Uniqueness, validating, 162–163
:unless
option, 83
update_attributes
method, 152–153
update_bound_check_box
method, 183–184
update_bound_controls
method, 186
update_*_controls
method, 181–182
update_speed
method, 153
Updating
attributes, 152–153
records
attribute_set
method, 152
original values versus dirty values, 153
overview, 152
save
method, 152
update_attributes
method, 152–153
update_speed
method, 153
updating attributes, 152–153
users, 62
upgrade_model_storage
method, 123–126
URI
property type, 155
URIs, storing as strings, 155
url
method
AbstractController
class, 71
Merb console, 11
URL methods, 71
URLs (Uniform Resource Locators)
absolute, returning, 71
deleting, 11
generating, 11
getting, 11
posting, 11
putting, 11
relative, returning, 71
retrieving, 11
router generation, testing, 50
router recognition, testing, 49–50
strings in, 155
User accounts
creating, 62
hijacking, 59–60
user_class
method, 231
Users
deleting, 62
listing, 61
profiles, displaying, 62
updating, 62
use_template_engines
method, 14
UUID
property type, 155
UUIDs, storing as strings, 155
validates_absent
method, 162
validates_format
method, 162
validates_is_accepted
method, 162
validates_is_confirmed
method, 162
validates_is_number
method, 162
validates_is_unique
method, 162–163
validates_length
method, 162
validates_present
method, 162
validates_with_block
method, 162
validates_within
method, 163
validates_with_method
method, 162
Validations
automatic, 132
automatic, turning off, 132, 163
with blocks, 162
conditions, 163–164
confirming attributes, 162
contexts, 164
format of a value, 162
formats, 163
with methods, 162
numerical length, 162–163
numerical values, 162
overview, 162–163
presence of, 163
presence of a value, 162
within a range of values, 162–163
against regular expressions, 132
true values, 162
uniqueness, 162–163
validates_within
method, 163
Very flat application layouts, 3–6
very_flat
argument, 3–6
View methods, 71
View templates. See Flat application layouts.
Views. See also Templates.
authentication, 249–250
for ERB. See ERB (eRuby) views.
for HTML. See Haml views.
login, 249–250
Merb view templates, 109–111
partials, 111–112
templates within templates, 111–112
templating system, default, 101–102
for XML. See Haml views.
VirtualFile
class, 23
Warn messages, logging, 18
WebController
mixin, 265–266
WEBrick adapter, 25
webrick
key, 25
Weizenbaum, Nathan, 105
Whitespace
preserving, 108
removing, 102
sensitivity, 19
Widgets. See Parts.
with
method, registering routes with, 55. See also Register
method; To
method.
:with
option, 83
Worker queue, placing blocks in, 74
Worker threads, starting, 31
Workers, definition, 34
writable?
method, 271–272
write
method, 271–272
:writer
option, 131
Writing cache data, 271–272
XML entities, escaping, 74
XML MIME set, rendering views with, 71
YAML
configuration file, 114–115
files, 19–20
MIME set, rendering views with, 71
nodes, 115
storing as a string, 155
Yaml
property type, 155
18.191.61.243