Index

A

Action Controller

communication with view, 104–105

controller specs, 526–529

filters, 105–111

around, 109

classes 107

conditions, 110

halting chain, 111

inheritance, 106

ordering, 108

skipping, 110

layouts, specifying, 101

post-backs, 357

rendering, 92–101

standard RESTful actions, 61–64

streaming content, 112–116

verify method, 111–112

Action Dispatch, 88–91

Action Mailer, 471–481

attachments, 475, 476, 478

custom email headers, 473

generating URLs inside messages, 476

handing inbound attachments, 478

HTML messages, 474

mailer layouts, 476

models, 472

multipart messages, 475

preparing outbound messages, 472

raising delivery errors, 19

receiving, 477–479

sending, 477

server configuration, 479

SMTP, 471

testing with RSpec, 479–481

Action View, 293–308

conditional output, 296

customizing validation error output, 315

ERb, 293

filename conventions, 294

flash messages, 300–302

Haml, 293

instance variables, 297–302

layouts, 294–295

partials, see Partials.

view specs, 529–531

yielding content, 295

Active Model, 561–578

AttributeMethods module, 561–562

Callbacks module, 563

Conversion module, 563–564

Dirty module, 564

Errors class, 565

MassAssignmentSecurity module, 567

Naming module, 569

observers, 569–571

serialization, 571–573

testing compatibility of custom classes with Lint::Tests, 567

translation, 573

Validations module, 574–578

Active Resource 459–471

authentication, 465

customizing default URLs, 463

Active Record

abstract base models, 276

associations, 121, 181–230

:counter_cache option, 190, 195

:counter_sql option, 187

:dependent option, 187, 188, 195

:finder_sql option, 187

AssociationProxy class, 228–229

belongs_to. See belongs_to associations

checking inclusion of records in collection, 189

class hierarchy, 181

destroying records, 188

extensions, 226–227

foreign-key constraints, 281

has_and_belongs_to_many. See has_and_belongs_to_many associations

has_many :through. See has_many :through associations

has_many. See has_many associations

indexing, 484

many-to-many relationships, 208–214

one-to-many relationships, 183–190

one-to-one relationships, 222–225

polymorphic, 277–281

size of, 190

unique sets, 190

unsaved objects, 225

attributes, 123–126

controlling access, 140

readonly, 141

reloading, 131

serialized, 125

typecasting, 131

updating, 136–1140

Base class, 120

basic object operations, 127–133

calculation methods, 265–267

callbacks, 256–265

list of, 258–259

cloning, 131

concurrency. See Database locking

configuration, 158

dynamic finder methods, 132

dynamic scopes, 133

find_by_sql method, 133–134

legacy naming schemes, 122–123

model specs, 526–528

migrations, 161–179

column type mappings, 168–172

creating, 161–172

magic timestamp columns, 172

schema.rb file, 174

sequencing, 162

observers, 10, 268–269

pattern, 119

query caching, 135–136

querying, 146–152

exists, 152

from, 150

group, 150

having, 150

includes, 151

joins, 151

limit, 149

offset, 149

order, 148

readonly, 152

select, 149

where, 146–148

RecordInvalid exception, 187

RecordNotSaved exception, 187, 188

records

deleting, 141–142

random ordering, 148

touching, 139

scopes, 251–255

session store, 429

STI (Single-Table Inheritance), 269–276

translations, 386–388, 390

validations, 231–250

common options, 242–243

conditional validation, 243–245

contexts, 245

custom macros, 247–248

errors, 231–232, 249–250

enforcing uniqueness of join models, 240

reporting, 310–312

short-form, 245–246

skipping, 249

testing with Shoulda, 250

value objects, 281–285

Active Support, 579–686

Ajax, 409–425

changes in Rails 3, 410

CSS selectors, 418

HTML fragments, 421

JSON, 419–421

JSONP, 423–424

Unobtrusive JavaScript (UJS), 411–412

Array, extensions, 579–585

Asset hosts, 22, 321–323

Asset timestamps, 323

Asynchronous processing, See Background processing.

Atom Feeds

autodetection, 316–317

atom_feed method, 324–326

Authentication, 433

Active Resource, 465

client-side certificates, 466

HTTP basic, 465

HTTP digest, 466

Authlogic, 434

configuration, 437–438

B

background processing, 549–559

Base64 class, 586

BasicObject class, 586–587

belongs_to associations, 191–199

building and creating related objects, 192

options, 192–199

polymorphic, 197

reloading, 191

touch, 198

with conditions, 193

benchmarking, 587

binary data storage, 170

breadcrumbs, 400–401

Builder::XmlMarkup class, 454

Bundler, 2–7

loading gems directly from Git repository, 4–5

C

Caching

:counter_cache, 190, 195

action caching, 484–485

CacheHelper module, 326

controlling web caches and proxies, 497

disabling in development mode, 18

ETags, 498–500

expiration, 488–491

fetch, 496–497

fragment caching, 486–488

page caching, 484

query caching, 135–136

storage, 493

Store class, 590–595

sweeping, 491, 494

view caching, 483–495

Callbacks. See also Active Record, callbacks

in Active Support, 595–597

CAS, 443

CDATA, 366

chars proxy, 645–648

Class, extensions, 598

Concern module, 602

Concurrency. See Database Locking

Configurable module, 603

const missing method, 644

Controllers. See Action Controller

convention over configuration, 119, 122

Cookies

:secure option, 432

integrity, 11–12

reading and writing, 431

session store, 429

signing, 432

CRUD (Create Read Update Delete), 119

CSS

linking stylesheets to template, 318–319

sanitizing, 365

Currency

formatting, 359

Money gem, 284

D

data migration, 173–174

Databases

connecting to multiple, 153–154

foreign-key constraints, 281

locking, 142–146

considerations, 145

optimistic, 143

pessimistic, 145

migrations. See ActiveRecord, Migrations.

schemas, 15, 161

seeding, 175–76

using directly, 154–158

Date, extensions, 603–609

Date input tags, 328–331

DateTime, extensions, 609

Decent Exposure gem, 105, 297–298

decimal precision, 169, 171

Delayed Job gem, 550–553

Deprecation, 617

Devise gem, 439

Domain-Specific Languages, 291

Drag and Drop, 415

Duration class, 617–618

E

Email. See Action Mailer

Enumerable, extensions, 619–620

ETags, 498–500

Excerpting text, 370

F

Facebook, 443

favicon.ico file, 317

Files

extensions by Active Support, 621–622

reporting sizes to users, 359

upload field, 348, 356

Firebug, 410

floats, 171

Forms

_destroy checkbox, 345

_method hidden field, 64

accepts_nested_attributes_for method, 344–345

attributes not typecasted, 343

automatic view creation, 313–314

button_to helper method, 391

custom builder classes, 347

dynamically adding rows of child records, 338

helper methods, 333–358

input, 348–358

updating multiple objects at once, 337

G

Gemfile, 3

Geocoding, 260–261

H

has_and_belongs_to_many associations, 208–214

bidirectional, 210

custom SQL, 211–213

extra columns, 213

making self-referential, 209

has_many :through associations, 214–221

and validations, 218

join models, 215

options, 219–221

usage, 216

has_many associations, 199–208

:class_name option, 202

:conditions option, 202

:include option, 204–206

callbacks, 200–201

has_one associations, 222–225

options, 224–225

together with has_many, 223

Hash, extensions, 622–627

HashWithIndifferentAccess class, 627

Heckle, 534

Helper methods,

helper specs, 531

writing your own 398–407

HTML

escaping, 367

sanitizing, 364–365

tags

a, 392–394

audio, 319

label, 348

form. See Forms.

option, 353–355

password, 349

select, 350–351

script, 359

submit, 349

video, 320

HTTP

basic authentication, 465

foundation of REST, 55–56

stateless, 427

status codes, 99–101

verbs (GET, POST, etc.), 60–64, 393

I

IMAP, 443

Image tags, 320

Initializers, 11–14

backtrace_silencers.rb, 11

cookie_verification_secret.rb, 11–12

inflections.rb, 12–13

mime_types.rb, 14

session_store.rb, 14, 430

Inflections. See Pluralization

Integer, extensions, 632–633

Internationalization (I18n), 372–391

Active Model, 573

Active Record, 386

default locale, 10

exception handling, 391

interpolation, 385

locale files, 382–383

process, 380–390

setting user locales, 377–380

setup, 374–380

J

JavaScript, 97, 317–318, 358–259, 409–425

escaping, 358

including in template, 317–318

link_to method enhancements, 392–393

using to insert HTML into pages, 338

JQuery framework, 410–411, 418, 421, 423–424

JSON, 97, 419–421, 635–636

JSONP, 423–424

K

Kernel, extensions, 634–635

L

LDAP, 443

link_to helper methods, 392–394

Locale files, 382–383

Logging, 23–28

backtrace silencing, 11, 587

BufferedLogger class, 588–590

colorization, 27

level override, 15

levels, 23–24

log file analysis, 26–27

Logger, extensions, 635–637

Syslog, 28

M

Memcache, session store, 428

MessageEncryptor class, 636–637

MessageVerifier class, 637–638

Middleware (Rack), 86–88

MIME types, 13–14

Module, extensions, 638

MongoDB, 444

MVC (Model-View-Controller), 85

N

Named scopes. See Active Record, scopes.

Nonces, 430

Notifications, 651–652

Numbers

delimiters, 360

extensions to Numeric class, 650–653

conversion, 359–361

O

Object, extensions, 653

Observers, 10

OpenID, 443

OpenSSL Digests, 431

P

params hash, 336–338

Partials, 95, 302–307

passing variables to, 305

rendering collections, 306

reuse, 303

shared, 304

wrapping and generalizing, 401–407

Plugins, 535–548

as RubyGems, 536

extending Rails classes, 540

installation and removal, 542–543

load order, 9–10

plugin script, 536

rake tasks, 543–544

testing, 545–546

writing your own, 537–548

Pluralization

i18n, 385

Inflector class, 12–13

Inflections class, 628–632

pluralize helper method, 370

Prototype framework, 361, 411

helper methods, 361

Prototype Legacy Helper plugin, 413

R

Rack, 86–88, 90–91

Rack::Sendfile middleware, 114

RACK_ENV variable, 1

routes as Rack endpoints, 41–42

rails.js file, 411

Rails

Class loader and reloading, 16–18, 613–617

console, 12

reloading, 92

Engines, 549

lib directory, 17

root directory, 9

runner, 559

scaffolding, 311–314

settings, 1–29

application.rb file, 8–11

autoload paths, 9

boot.rb file, 8

cherry-picking frameworks used, 8

custom environments, 20

development mode, 15–19

environment.rb file, 8

generator defaults, 11

initializers. See Initializers

production mode, 20–23

test mode, 19–20

RAILS_ENV variable, 1

Railties, 546–547, 658

Rake tasks (selected),

db:migrate, 163, 176

log:clear 24

routes, 53

spec, 521

Random

ordering of records, 148

SecureRandom generator class, 661–662

Range, extensions, 658–659

RecordNotFound exception, 128

Regexp, extensions, 660

Rendering views, 92–101

another actions’s template, 93

explicit, 93, 94

implicit, 92–93

inline templates, 96

JSON, 97

nothing, 97

options, 98

partials, see Partials.

text, 96

XML, 97

Request handling

in routing, 89

redirecting, 101–104, 418

verification, 111–112

Rescuable module, 662

Resque gem, 553–557

REST and RESTful design, 55–83

action set, 78–82

collection routes, 72

controller-only resources, 74

forms, 335

member routes, 70–71

HTTP verbs, 60–64

nested resources, 65–69

routes, 31, 58–61

resources and representations, 40–41, 56–57, 76–77

singular resource routes, 64–65

standard controller actions, 61–64

REXML, 456, 686

Roy T. Fielding. See also REST and RESTful design, 55–58

Routing, 31–54

constraining by request method, 38–39

formats, 40

globbing, 45–46

listing, 53

match method, 34–37

named, 46–50

RESTful routes, 31, 58–61

:format parameter, 76

collection, 72

member, 70–71

nested, 65–69

singular, 64–65

redirecting, 39–40

root routes, 44–45

routes.rb file, 33–34

scopes, 50–53

RJS, 412–419

templates, 413

RSS autodetection, 316–317

RPX authentication, 445

RSpactor, 531

RSpec, 501–533

assertions, 510

custom expectation matchers, 514

generator settings, 11

grouping related examples, 504

let methods, 504–506

mocking and stubbing, 517–520

pending, 509–510

predicate matchers, 513–514

running specs, 520

runtime options, 522

shared behaviors, 517

spec_helper.rb file, 515, 522–524

subjects, 511–513

testing email, 449–481

Ruby

$LOAD_PATH, 9, 16

hashes, 450

macro-style methods, 121

Marshal API, 425

modules for reusing common behavior, 285–289

RubyGems

as plugins, 536

Bundler, 2–7

Git repository, loading directly from, 4

installing, 5–7

packaging, 7

using pre-release gems, 4

S

Scopes, see Active Record, scopes

Security

CSRF attacks, 336

replay attacks, 429

SQL injection, 134

Session Management, 425–432

cleaning old sessions, 430

storage

RESTful considerations, 75

turning off sessions, 427

Settings, 1–29

Specjour, 532

Spork, 532

SSL

OpenSSL digests, 429

serving protected assets, 323

X.509 certificates, 465–466

Static content, 116

Streaming, 112–116

String,

extensions, 662–671

usage versus symbols, 130

StringInquirer class, 671

SOAP, 457

Symbol,

extensions, 671

usage versus strings, 130

T

Templates. See View templates.

Thread safety, 22–23

Time

extensions, 673–680

input tags, 328–331

reporting distances in time, 332–333

storing in database, 170

Time Zones

DateTime conversions, 612

default, 10

option tags helper, 354–355

TimeZone class, 681

TimeWithZone class, 680

Truncating text, 372

U

Unicode, 364, 385, 648–649

Unobtrusive JavaScript (UJS), 411–412

URL

generation, 395–398

patterns in routing, 35–36

segment keys, 36–38

V

Validation. See Active Record, validations

Value objects, 281–285

View templates. See also Action View, 293–308

capturing block content, 326–327

concat method, 368

cycling content, 369

debugging output, 333

encapsulating logic in helper methods, 399

highlighting content, 370

localization, 373

raw output, 361

record identification, 362–364

transforming text into HTML, 371

translation. See Internationalization.

word wrap, 372

Visual effects, 419

W

Watchr, 532

Web 2.0, 332, 423

Web architecture, 55–56

Whiny nils, 18

X

XML, 445–457

parsing, 456

to_xml method, 445–454

Active Record associations, 448

customizing output, 446–448

extra elements, 452

overriding, 453–455

Ruby hashes, 450

typecasting, 457

XML Builder, 454–456

XMLHttpRequestObject, 409

XMLMini module, 684–686

Y

YAML, 125–126, 445

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.250.203