Index

Note: Page numbers in italics indicate figures, those with t indicate tables, and those with n indicate footnotes.

Symbols

/ (slash)

root URL, 60

Unix directory separator, 8

== (equal signs)

assignment operator, 423-424, 438-439

equality operator, 164

(backslash)

as escape character, 155

as literal character, 155

" " (double quotes)

defining strings, 155

exchanging for single quotes, 155

mixing with single quotes, 136

: (colon), as a hashkey, 171-172

!! (exclamation points), coercing Boolean values, 158, 295

!= (exclamation point, equal sign), not equal operator, 164

' (single quotes), mixing with double quotes, 136

[ ] (square brackets), accessing elements, 164

@ (at sign), instance variables, 72, 224

/* ... */ (slash, asterisk), CSS comments, 205

&& (ampersands), and operator, 157, 376-377

+ (plus operator), concatenating strings, 153

<<(less-than signs), adding to arrays, 165

||= (vertical bars, equal sign), or equals

assignment operator, 387-388

! (exclamation point)

bang methods, 165

not operator, 157

? (question mark)

boolean indicator, 156

in query parameters, 528

( ) (parentheses)

in statement syntax, 424n

and the ternary operator, 437n14

{ } (curly braces)

block indicator, 167

hash indicator, 171

# (hash symbol)

comment indicator, 21, 152

styling CSS IDs, 726

styling CSS IDs (Listing 5.9), 208

URL stub, 198

# (pound sign). See # (hash symbol).

=> (equal, greater than), hashrocket, 171

||(vertical bars)

block variable indicator, 167

or operator, 157

$ (dollar sign)

command line prompt, 8

dollar-sign syntax, 726

Sass variables, 224

10 types of people, 438-439

A

-a flag, 43

About page

creating, 115-118, 118

mockup, 235

sample page, 118

testing, 114

Abstraction layers, 252n

Acceptance tests, 463

Account activation

edit action (Listings 11.31 to 11.32), 545-549

generalized authenticated? method (Listings 11.26 to 1.29), 543-545

metaprogramming, 541

overview, 515-516, 540

preventing unactivated users from logging in (Listing 11.32), 545-549

versus remembering, login, and password reset, 516t

sign-up page with warning message, 548

successfully activated profile page, 547

Account activation mailer method

account activation HTML view (Listing 11.14), 529

account activation text view (Listing 11.11), 529

Action Mailer library, 525

adding account activation to user sign-up (Listing 11.23), 536-537

assert_match method (Listings 11.19 to 11.20), 534-535

commenting out failing tests (Listing 11.24), 537

creating an activation email (Listings 11.6 to 11.14), 525-529

email, sent in production, 558

email previews (Listings 11.16 to 11.18), 530-533

escaping out special characters, 528

generating a mailer (Listings 11.6 to 11.14), 525-529

Home page with activation message, 538

mailing the account activation link (Listing 11.12), 527

query parameters, 528

sample activation email (Listing 11.25), 538-540

setting the test domain host (Listing 11.21), 535

User mailer test (Listings 11.19 to 11.21), 533-536

User mailer test, screen mockups, 532-533

Account activation resource

activating fixture users (Listing 11.5), 523-524

activating seed users (Listing 11.4), 523

activation tokens, 516, 520-522

adding a resource (Listing 11.1), 518

method reference technique, 521

migration for account activation (Listing 11.2), 519-520

overview, 516-524

User model with account activation attributes, 520

Account activation test

activation via user model object (Listing 11.37), 552-553

integration test (Listings 11.33 to 11.37), 549-553

overview, 549

sending email via user model object (Listing 11.36), 552

user activation methods in the User model (Listing 11.35), 551-552

user sign-up test (Listing 11.33), 550-551

Action Mailer library, 525

Actions, corresponding views (Listings 3.9, 3.10), 107

Activation tokens, 516, 520-522

Active Record. See also SQL (Structured Query Language); Validating user data.

definition, 248

finding User objects, 260-261

initializing objects, 257

making and saving a model, 257-259

uniqueness, at the database level (Listings 6.29 to 6.34), 281-286

uniqueness, validating (Listings 6.24 to 6.34), 278-286

validating users, 263-264. See also Validating user data.

validity, 257

Active Record::RecordNotFound exception, 260

Active relationships, 685, 685

add_column method (Listing 6.35), 288

add_index method, 282

Adler, Yoel, 480n

admin attribute (Listings 10.54 to 10.56), 502-505

admin? boolean method (Listings 10.54 to 10.55), 502-503

Administrative users

admin attribute (Listings 10.54 to 10.56), 502-505

admin? boolean method (Listings 10.54 to 10.55), 502-503

deleting (Listings 10.54 to 10.55), 502-503, 501

identifying (Listings 10.54 to 10.55), 502-503

Ajax (Listings 14.34 to 14.39), 723-727

Ampersands (&&), and operator, 157, 376-377

Anonymous functions, 614

any? method, 338

app/assets directory, 218

ApplicationController class (Listing 2.22), 85-87, 86, 87

application.html.erb file, 128-129

application.html.erb file (Listings 4.3, 5.1), 148, 195-196

Applications

getting started. See Hello world program.

interacting with. See Console.

renaming, 50

samples. See Hello world program; Static pages; Toy application.

Architectural Styles and the Design of Network-based Software Architecture (Fielding), 70n

Arrays. See also Ranges.

! (exclamation point), bang methods, 165

!= (exclamation point, equal sign), not equal operator, 164

[ ] (square brackets), accessing elements, 164

== (equal signs), equality operator, 164

adding to, 165

associative, 170

bang methods, 165

classes, 177

converting ranges to, 166

converting strings to, 163

converting to strings, 165

versus hashes, 170-172

indexing, 163

mutating, 165

pulling out elements, 166

selecting every element, 166

of strings, 272

zero-offset, 163

assert method (Listings 6.4 to 6.5), 265

assert_match method (Listings 11.19 to 11.20), 534-535

assert_select method

examples of (Listing 5.33), 238t

sign-up failure, 342

testing for HTML tags (Listing 3.24), 120

Asset directories, 218

Asset pipeline

asset directories, 218

definition, 218

manifest files (Listing 5.19), 218-219

preprocessor engines, 219-220

production efficiency, 220

Associations between Micropost models (Listings 13.10 to 13.12), 608-611, 609t

Associative arrays. See Hashes.

At sign (@), instance variables, 72, 224

attr_accessible method, 333

attr.accessor method (Listing 4.17), 250

Attribute accessors, creating, 188

authenticate method

authenticating passwords, 293-296

authenticating users (Listing 8.7), 376

examples (Listing 8.7), 377t

authenticated? method (Listings 11.26 to 1.29), 543-545

Authenticating users (Listing 8.7), 376, 377t

Authentication

versus authorization, 467

passwords, 293-296

Authentication systems, rolling your own, 247-248

Authenticity token, sign-up forms, 328

Authorization, friendly forwarding

create action (Listing 10.32), 482

implementation code (Listing 10.30), 480

logged_in_user before filter (Listing 10.31), 480-481

overview, 478-483

redirect_back_or method (Listing 10.32), 481-482

testing for (Listings 10.29 to 10.32), 478-483

Authorization, requiring logged-in users

adding a logged_in_user method (Listings 10.15), 468-469

before_action command (Listing 10.15), 467-469

before filters (Listing 10.15), 467-469

logged_in_user before filter (Listings 10.15), 468-469

logging in a test user (Listing 10.15), 468-471

login form mockup, a protected page, 468

login form mockup, access failure, 468

overview, 467-473

testing edits (Listings 10.20 to 10.21), 471-473

Authorization, requiring the right user

adding a user to the fixture file (Listings 10.23 to 10.28), 473-478

correct_user before filter (Listings 10.27 to 10.28), 476-478

current_user? method (Listings 10.27 to 10.28), 476-478

overview, 473-478

testing a correct user (Listings 10.27 to 10.28), 476-478

testing the wrong user (Listing 10.24), 474

Authorization versus authentication, 467

Automated testing

getting started, 112

Green results, 114-117

Guard program, 137-143

overview, 110-111

Red, Green, Refactor, 113-118

Red results, 113-114

refactoring, 117-118

timing tests, 110-111

aux options, 142-143

Avatar, definition, 314n

B

Backing up code, 37

Backslash ()

as escape character, 155

as literal character, 155

Bang bang (!!), coercing Boolean values, 158, 295

Bang methods, 165

bar, word origin, 153n

Base titles, 147

Bash command-line interface, 14

bcrypt hash function (Listing 6.36), 288-289, 294n22

Before filters (Listing 10.15), 467-473

before_action command (Listing 10.15), 467-473

before_filter command, 467n

belongs_to associations (Listings 11.9, 13.10, 14.3), 608-611, 689

Bitbucket (Listing 1.12)

overview, 36-40, 39

pushing changes up to, 39

Blank? method, 184

Bloc, 6

Block variables, definition, 167

Blocks

as closures, 168n

definition, 167

map method, 168

multiline, 168

overview, 167-170

Books and publications. See also Online resources.

Architectural Styles and the Design of Network-based Software Architecture (Fielding), 70n

“Class and Instance Variables in Ruby,” 182n

Learn Enough Command Line to be Dangerous, 1

Learn Enough Git to be Dangerous, 32

Learn Enough Text Editor to be Dangerous, 41n

Patterns of Enterprise Application Architecture (Fowler), 248n1

prerequisites for Rails, 5-6

Pro Git, 40n

“The Rails 3 Asset Pipeline in (about) 5 minutes” (Erasmus), 217n

“Rails Routing from the Outside In,” 701n

Ruby on Rails Tutorial website, 2n

Boolean values

combining, 157

in control flow, 156

identifying, 156

Bootstrap, drop-down menus (Listing 8.20), 393-394

Bootstrap and custom CSS. See also Site layout.

adding CSS (Listings 5.6 to 5.9), 205-210

adding the bootstrap.sass gem (Listing 5.5), 204

color (Listing 5.9), 210

Home page mockup, 206, 208, 211

installing Bootstrap, 204

overview, 202-204

site logo (Listing 5.9), 210

typography (Listing 5.8), 208, 208-210

bootstrap.sass gem (Listing 5.5), 204

bootstrap-will_paginate method (Listings 10.44 to 10.46), 492-494

box_sizing, 305-306

Branches. See also Git, branching.

current branch, identifying, 42

definition, 41

deleting, 44

editing, 43

listing, 42

merging, 43-44

pushing changes up to the Bitbucket, 39

status, displaying, 43

Built-in classes

adding methods to, 417-418

modifying, 183-184

Built-in functions, 146

bundle command, 23n, 99

bundle exec, 60

Bundler, 18-23

Buttons, web page

follow buttons, 682, 708

follow buttons (Listing 14.40), 727-729

linking to (Listing 5.45), 242-244

unfollow buttons, 681-682, 709

unfollow buttons (Listing 14.40), 727-729

byebug gem (Listing 3.2), 312

C

Callbacks, databases, 283

CamelCase, 101

CarrierWave uploader

adding to the Gemfile (Listing 13.58), 657-659

configuring for production (Listings 13.69 to 13.71), 671-674

data model for microposts, 659

description, 657-663

MiniMagick interface (Listing 13.67), 669-670

uploading images (Listings 13.59 to 13.62), 659-663

uploading images in production (Listings 13.69 to 13.71), 671-674

validating images (Listings 13.64 to 13.66), 664-667

Cascading Style Sheets (CSS). See CSS (Cascading Style Sheets).

Case sensitivity

downcasing email addresses (Listing 6.32), 283

email addresses (Listings 6.26 to 6.27), 279-280

indices (Listings 6.32 to 6.34), 283-286

SQL, 614n

cat command (Listing 1.11), 37-38

cd (change directory) command, 14-15t

Célio, Paulo Júnior, 428n

Change directory (cd) command, 14

change method (Listing 6.2), 252

Changes, overwriting, 36

checkout (co) command, 36

Clark, Mike, 7

Clark, Nicole, 7

“Class and Instance Variables in Ruby,” 182n

Class methods, 179

Class names, converting to IDs, 688n

Classes. See also CSS classes.

arrays, 178

attribute accessors, creating, 188

built-in, adding methods to, 417-418

built-in, modifying, 183-184

checking for palindromes, 180-183

class methods, 179

constructors, 178-179

defining (Listing 4.15), 181-183

definition, 106

description, 177

getter methods, creating, 188

hashes, 178

hierarchy, determining, 179-180

inheritance, 179-183, 182

instance method, 179

instance variables, creating, 188

instances of, 179

literal constructors, 178

named constructors, 178

new method, 178

self keyword, 182-183

setter methods, creating, 188

Static Pages controller, 185-187

superclass method, 179-180

User class (Listing 4.17), 187-190

Client computer, definition, 104

Closures, 168n

Cloud integrated development environment. See Cloud9.

Cloud storage

for micropost images, 671-674

S3 (Simple Storage Service), 672-674

Cloud9. See also Installing Rails on Cloud9; Local development environment.

creating a new workspace, 11, 12

Find in Files global search, 10

getting started, 11-12

local servers, sharing, 26

Rails Tutorial Cloud9 workspace, 10

setting code indentation, 12, 12

signing up, 11

co (checkout) command, 36

Code generation, undoing, 102-103

Code School, 6

coffee file extension, 219-220

Collisions, checking for, 412n6

Colon (:), as a hashkey, 171-172

Color (Listing 5.9), 210

Columns, in databases, 250

Commands. See also specific commands

Heroku, 50-51

Unix, 14-15t

Commenting out failing tests (Listing 11.24), 537

Comments

/* ... */ (slash, asterisk), CSS comments, 205

# (hash symbol), comment indicator, 21

# (pound sign), comment indicator, 152

in the console, 152

commit command, 35, 43

Commit messages, displaying, 35

Committing changes, 35, 43

Concerns technique, 382n

config directory, listing contents of, 103

Confirmation of passwords, 293-296

Confirmation of passwords (Listings 6.37 to 6.40), 289-291

Console

˜irb configuration (Listing 4.8), 151

comments, 152

definition, 150

environments, 151, 302-306

exiting, 151

message chaining, 157

message passing, 156-159

method definitions, 159-161

in Micropost resource, 82

objects, 156-159

prompts, 82n

starting, 150-151

strings, 153-155

toy application, 82

console command, 82

Constructors, 178-179

Contact page

adding actions (Listing 5.24), 229-230

adding routes (Listing 5.23), 229

integration test for layout links (Listing 5.32), 236-238

named routes (Listings 5.27 to 5.28), 230-231

root routes (Listing 5.23), 228-230

testing (Listing 5.21), 228-230

view for (Listing 5.25), 230

content_for function, 126n14

Controller class. See Static Pages controller.

Controller tests. See Testing, Static Pages controller.

Controllers, generating (Listing 3.6), 100-107. See also Sessions controller; Static Pages controller.

Conventions in this book, 8-9

Converting

arrays to strings, 165

ranges to arrays, 166

strings from objects, 157

strings to arrays, 163

Cookies

decrypting, 419

encrypting, 418

expiration, 417-425

inspecting, 425n

permanent, 417-425

remembering user login, 410

session hijacking, 410, 412n5

signed, 418

stealing, 410

storing userid in, 418-419

cookies method, 366

cookies.permanent method, 417-425

Coordinated Universal Time (UTC), 258n7

correct_user before filter (Listings 10.27 to 10.28), 476-478

count method

showing microposts, 620

sign-up failure, 341

Counter cache, showing microposts, 620

cp (copy files) command, 14-15t

create action

creating microposts (Listing 13.36), 635-636

friendly forwarding (Listing 10.32), 482

password reset (Listings 12.5 to 12.6), 571-573

sign-up failure (listing 7.18), 329-332

sign-up success (Listing 7.28), 346-349

strong parameters (Listing 7.19), 334

view template (Listing 7.28), 346-348, 347

create command, 48

Create directory (mkdir) command, 14

create method, creating users, 259, 293-296

create_table method (Listing 6.2), 252

Creating

About page, 115-118, 118

an activation email (Listings 11.6 to 11.14), 525-529

attribute accessors, 188

database indices, 281

fixtures (Listings 8.21 to 8.22), 397-398

following relationships (Listings 14.38), 727

getter methods, 188

Help pages, 100

instance variables, 188

microposts. See Microposts, creating.

persistent sessions, 410

remember me checkbox (Listings 9.21 to 9.23), 433-438

sample users (Listings 10.42 to 10.43), 489-491, 490-491, 491

Sessions controller, 366-369

Creating (continued)

setter methods, 188

Static Pages controller class (Listing 3.20), 185-187

temporary sessions (Listing 8.13), 382-383

User objects, 256-260

user profile pages, 307-311

users, 62-66, 62-63, 259, 293-296

Creating, microposts

adding to the Home page (Listing 13.37), 636-637

create action (Listing 13.36), 635-636

creating (Listings 13.36 to 13.45), 635-642

form for creating microposts (Listing 13.37), 635

redefining error messages (Listings 13.41 to 13.45), 639-642

user info sidebar (Listing 13.38), 637

CSRF (cross-site request forgery), 328

CSS (Cascading Style Sheets). See also Site layout.

{ } (curly braces), hash indicator, 176

including style sheets (Listing 4.1), 175-177

rules, bundling and reusing. See Sass mixins (Listing 7.2).

Sass mixins (Listing 7.2), 304-306

stylesheet_link_tag function, 146, 177

styling error messages with (Listing 7.22), 339-340

tool for. See Sass utility.

CSS classes, 197-202

.css file extension, 205

Ctrl-C keystroke

case sensitivity, 24

restarting the console, 151

shutting down a server, 24

Ctrl-D keystroke

case sensitivity, 82

exiting Guard, 143

exiting the console, 82

curl utility, 200-201

Curly braces ({})

block indicator, 168

hash indicator, 171, 176

Current user, finding (Listings 8.16 to 8.17), 389-390

current_user, updating (Listing 9.9), 424-425

current_user method (Listings 8.16 to 8.17), 389-390

current_user? method (Listings 10.27 to 10.28), 476-478

Custom environments, 302n

D

-d flag, 44

-D flag, 44

Data models

associations (Listings 2.14, 2.15), 81-82, 82

toy application, 57-59, 57-59, 72

Data structures. See also CSS (Cascading Style Sheets).

arrays, 163-167

blocks, 167-170

hashes, 170-172

ranges, 163-167

symbols, 172-175

Data validation, toy application, 74. See also Validating user data.

Database indices, creating, 281

Database migration. See also Rake db:migrate command.

definition, 251

dropping tables, 254

magic columns, 252, 258

migrating down, 254

migrating the User model (Listing 6.2), 251-254

migrating up, 252

migration file name, 252

reversing. See Undoing, database migration.

rolling back. See Undoing, database migration.

in a sandbox, 256-257

timestamp, 252

undoing, 102-103, 254, 256, 294n21

Databases. See also User model.

callbacks, 283

case sensitive indices (Listings 6.32 to 6.34), 283-286

columns, 250

full-table scan, 281

interacting with. See Active Record; SQL (Structured Query Language).

method reference convention, 283

resetting, 294n21. See also Undoing, database migration.

reversing changes. See Undoing, database migration.

rolling back changes. See Undoing, database migration.

rows, 250

tables, 250

Date and time, User objects, 258

db/development.sqlite3 file, 253

db:rollback command, 254

db/seeds.rb file (Listing 10.43), 490

de Ron, Niels, 428n

Debug, and Rails environments (Listing 7.1), 301-306

Debug box, sample code (Listing 7.21), 304

Debug information, sign-up failure (Listing 7.18), 330-333

debug method (Listing 7.1), 302

debugger

byebug gem (Listing 3.2), 312

use for, 312-313

with Users controller (Listing 7.6), 312

Decrypting cookies, 419-420

Default scope for Micropost models (Listings 13.14 to 13.17), 612-615

default_scope method (Listing 13.17), 614

DELETE method, 104-105

DELETE requests from web browsers, 392n

Deleting. See also destroy action; Destroying.

branches, 44

files and directories, 36

recursively, 36

Deleting, users

administrative users (Listings 10.54 to 10.55), 502-503, 501

destroy action (Listings 10.57 to 10.59), 505-508

overview, 500

strong parameters (Listing 10.56), 504-505

testing destroyed users (Listings 10.60 to 10.62), 508-511

users index with delete links, mockup, 501

dependent: :destroy method (Listings 13.19 to 13.20), 615-616

Deployment

overview, 45-46

tools for. See Heroku.

toy application, 88-89, 89

Deployment, professional grade

overview, 358

SSL certificates, 359

SSL (Secure Sockets Layer) in production (Listing 7.36), 358-359

destroy action

deleting sessions (Listings 8.29 to 8.32), 403-405

deleting users (Listings 10.57 to 10.59), 505-508

destroying microposts, 650-652

destroy command, 102

Destroying. See also DELETE method; Deleting.

following relationships (Listing 14.39), 727

Micropost model users (Listings 13.19 to 13.20), 615-616

microposts, 650-652

sessions (Listings 8.29 to 8.32), 403-405

things on a remote server, 105

User objects, 259

users, toy application, 63-66, 65

Development environment

cloud. See Cloud9.

setting up. See Cloud9.

Development environments, 302n

development.sqlite3 file, 253

Dictionary attacks, protection from, 294n22

Directories

contents, listing, 36

deleting, 36

updating the modification timestamp, 116-117

Displaying. See also Listing; Showing.

branch status, 43

commit messages, 35

email addresses, 310

.gitignore file, 142

IP binding address, 23

port number, 23

sign-up error messages (Listings 7.20 to 7.22), 336-340

user names, 310

Displaying user data

custom environments, 302n

debug, and Rails environments (Listing 7.1), 301-306

development environments, 303

lorem ipsum text, 301, 622n–623n

production environments, 303

Rails environments, 302-306

show page, mockups, 311

test environments, 303

user email addresses, 310

user names, 310

user profile page, mockup, 300

Users controller with a show action (Listing 7.5), 310

div tag, 197-198

Doctype declarations (Listing 3.23), 120

Document divisions, 197-198

Document type (Listing 3.23), 119

Dollar sign ($)

command line prompt, 8

dollar-sign syntax, 726

Sass variables, 224

Double quotes (" ")

defining strings, 155

exchanging for single quotes, 155

mixing with single quotes, 136

Downcasing email addresses (Listing 6.32), 283

Drop-down menus, mockup, 395

drop_table command, 254

DRY (Don’t Repeat Yourself) principle, 125

Duplication, eliminating. See Refactoring code.

Dynamic content, page titles

base titles, 147

on every page. See Base titles.

full_title helper function (Listings 4.2, 4.3, 4.11), 147-48, 162

HTML structure of a typical web page (Listing 3.23), 119

layout files (Listing 3.35), 128-129

list of sample pages, 119t

missing page titles, 147

overview, 118-119

RED testing, 119-121

templates for. See Embedded Ruby.

yield function, 126

E

each method, 174, 272

edit action

account activation (Listings 11.31 to 11.32), 545-549

password reset (Listings 12.14 to 12.15), 581-583

updating users (Listings 10.1 to 10.4), 452-457

Edit form, updating users (Listing 10.3), 454

Edit form mockups

initial edit page, 455

unsuccessful edits, 461

updating users, 455

user edit page, 452

Edit view (Listing 10.2), 454

Editing

branches, 42

Git branches, 43

Rails router, 29-30

user information, toy application, 62, 62, 63-64

elseif statement, 157

Email. See also Account activation mailer method; Password reset mailer method.

account activation, sample (Listing 11.25), 538-540

email via user model object (Listing 11.36), 552

fixtures (Listing 6.30), 282

generating an account activation mailer (Listings 11.6 to 11.14), 525-529

mailing the account activation link (Listing 11.12), 527

User mailer test (Listings 11.19 to 11.22), 533-536

User mailer test, screen mockups, 532-533

Email, sending in production

configuring SendGrid (Listing 11.41, 12.23), 556-557, 595-597

overview, 556-557, 595-597

Email addresses

displaying, 310

user names as, 250n

validating user data (Listings 6.18 to 6.23), 272-277

Email addresses, validating

case sensitivity (Listings 6.26 to 6.27), 279-280

downcasing (Listing 6.32), 283

format (Listings 6.18 to 6.21), 272-277

with regular expressions (Listing 6.21), 274-277, 275t

uniqueness (Listings 6.23 to 6.34), 278-286

uniqueness at the database level (Listings 6.29 to 6.34), 281-286

Email previews (Listings 11.16 to 11.18), 530-533

Embedded Ruby (Listings 3.31 to 3.40), 126-132

empty? method, 156-157, 338

Enabling SSL, 358-359

Encrypting cookies, 418

Encryption versus hashing, 287n19

Environments, in the console, 151. See also Development environment; Production environment; Test environment.

Equal, greater than (=>), hashrocket, 171

Equal signs (==)

assignment operator, 423-424, 438-439

equality operator, 164

Erasmus, Michael, 217n

ERb. See Embedded Ruby.

.erb file extension, 219-220

Error messages

failed micropost creation, 80, 80, 80

Googling, 5

invalid multibyte character, 30n

Rails Tutorial help, 9

redefining, microposts (Listings 13.41 to 13.45), 639-642

Spring process ID (pid) file will be overwritten, 135n

toy application, 80

You have not declared a Ruby version, 361

error_explanation (Listing 7.22), 339-340

_error_messages.html.erb partial file (Listing 7.21), 337-338

Escaping out special characters, 528

Exceptions

definition, 260

raising (Listing 9.29), 445-446

removing (Listing 9.33), 448

Exclamation point (!)

bang methods, 165

not operator, 157

Exclamation point, equal sign (!=), not equal operator, 164

Exclamation points (!!), coercing Boolean values, 158, 295

Expiration of cookies, setting, 417-425

Expressions, short-circuit evaluation, 388. See also Regular expressions.

F

f flag, 36

Failed password reset, 589

Failure-page mockups, 330-331

Faker gem

adding to the Gemfile (Listing 10.42), 489-490

creating sample data, 490-491

lorem ipsum text, 301, 622n–623n

Feed. See Microposts, proto-feed.

@feed_items instance variable (Listings 13.47 to 13.50), 645-649

Fielding, Roy, 70

field_with_errors class (Listing 7.22), 339-340

File compression, uglifier gem, 21

File navigator, advanced testing, 140-141

Files

blank, creating, 116-117

creating with touch command, 116-117

deleting, 36

GIT staging area, 33

updating the modification timestamp, 116-117

Find in Files global search, 10

find method (Listing 7.5), 386-389

find_by method, finding users (Listings 8.7, 8.16), 376, 386-389

Finding

User objects, 260-261

users (Listings 8.16 to 8.17), 389-390

Fioravanti, Paul, 685n

Firehose Project, 7

First application. See Hello world program.

first_user variable, 82

Fixtures

adding a digest method (Listings 8.21 to 8.22), 397-398

creating (Listings 8.21 to 8.22), 397-398

definition, 396

Flash, in sessions

code for failed login (Listings 8.9 to 8.12), 379-382

flash test (Listings 8.9 to 8.12), 379-382

flash.now method (Listing 8.11), 381

rendering with a flash message (Listing 8.8), 377-379, 377t

Flash messages (Listings 7.29 to 7.31), 349-351

flash.now method (Listing 8.11), 381

Flow control, 438-439

Follow buttons

mockups, 682, 708

testing (Listing 14.40), 727-729

Followed users (Listings 14.8 to 14.10), 692-695

Followers

definition, 681-682

Relationship model (Listings 14.12 to 14.13), 695-697

testing for (Listing 14.13), 697

Followers page, following user mockups, 712, 716

followers.include? method (Listing 14.13), 697

Following an unfollowed user, 722

Following associations (Listings 14.8 to 14.10), 692-695

Following page

following user mockups, 711

users following mockups, 715

Following relationships

creating (Listing 14.38), 727

destroying (Listing 14.39), 727

testing (Listing 14.40), 727-729

Following users, definition, 681-682

Following users, Relationship model

active relationships, 685, 685

adding indices (Listing 14.1), 686-687

association methods, summary of, 690t

belongs_to associations (Listings 11.9, 13.10, 14.3), 689

data model, 686

data model problem, 681-687

enforcing uniqueness, 687

followed users (Listings 14.8 to 14.10), 692-695

followers (Listings 14.12 to 14.13), 695-697

followers.include? method (Listing 14.13), 697

following association (Listings 14.8 to 14.10), 692-695

foreign keys, 688

has_many associations (Listing 14.2), 687-689

has_many :through association (Listings 14.8 to 14.10), 692-695

multiple-key indices, 687

passive relationships, 685

passive relationships (Listings 14.12 to 14.13), 695-697

passive relationships, model for, 696

Twitter-style relationships, 682

user.followers method (Listings 14.12 to 14.13), 695-697

user.following method (Listings 14.8 to 14.10), 692-695

validations (Listings 14.4 to 14.5), 690-691

Following users, status feed

initial status feed (Listing 14.44), 732-735

join method, 734

map method, 733

motivation and strategy (Listing 14.42), 731-732

sample, 730

subselects (Listings 14.45 to 14.47), 736-740

Following users, web interface

access control for relationships (Listings 14.31 to 14.33), 720-721

displaying statistics, 701, 704

displaying statistics (Listings 14.15 to 14.23), 700-710

follow buttons, creating (Listings 14.31 to 14.33), 720-721

followers action (Listing 14.25), 712-713

following action (Listing 14.25), 712-713

following/followers pages (Listings 14.24 to 14.29), 710-718

follow/unfollow forms (Listings 14.15 to 14.23), 700-710

Relationships controller (Listing 14.32), 720

resources block, 699

routes for user relationships (Listing 14.20), 706-707

sample following data (Listing 14.14), 698-699

show_follow view (Listing 14.26), 713-714

testing authorizations (Listing 14.24), 710-711

Following-user mockups

following an unfollowed user, 722

status feed on the live web, 740

unfollowed user, 722

user followers page, 712, 716

users following page, 711, 715

Following-user mockups, Home page

with follow statistics, 704

incremented followers count, 684

status feed, 684, 730, 739

Following-user mockups, user profiles

basic page, 680

finding a user to follow, 681

follow button, 681-682, 708

incremented followers count, 681-682

unfollow button, 681-682, 709

foo, word origin, 153n

foobar, word origin, 153n

.footer classes (Listing 5.15), 214n

footer tag (Listing 5.15), 214n

Footers

Home page mockup, 215

partials for (Listings 5.15 to 5.17), 214-216

site layout (Listings 5.15 to 5.17), 214-216

Foreign key reference, 603n

Foreign keys, 688

forget method (Listing 9.11), 426-427

forgot password form. See also Password reset.

basic, 563

invalid email address, 573

modified, 570

valid email address, 579

forgot password link, 562

form tag, sign-up forms, 328

form_for helper, 371-372

form_for method, 320-324

form_tag helper, 371n

Fowler, Martin, 248n1

FUBAR, word origin, 153n

Full-table database scan, 281

full_title helper function (Listings 4.2, 4.3, 4.11), 147-48, 162

Functions. See also Methods.

anonymous, 614

built-in, 146

definition, 106

implicit return, 160

versus methods, 156n

nameless. See Anonymous functions.

Functions, helpers. See also specific helpers

definition, 147

specific to a particular controller, 147n

G

gem command

installing Rails, 12-13

specifying a version range (Listings 1.1 to 1.5), 12-13

Gemfile

static pages (Listing 3.2), 94-95

updating (Listing 2.1), 54-55

generate command (Listing 3.6), 100

generate model command, 251

Generating code. See Scaffolding.

GET method, 104-105

Getter methods, creating, 188

Getting started. See also Books and publications; Online resources.

with Cloud9, 11-12

exercises, 7

first application. See Hello world program.

introduction, 4-5

overview, 1-4

prerequisites, 5-7

Git

adding the public key, 37-39, 38

backing up code, 37-40

benefits of, 35-36

Bitbucket (Listing 1.12), 36-40, 39

cat command (Listing 1.11), 37-38

checkout command, 36

deleting files and directories, 36

f flag, 36

GitHub, 37

hosting sites, 36-37

listing directory contents, 36

ls command, 36

overwriting current changes, 36

preventing conflicts Spring server, 139

q command, 35

quitting, 35

README file. See README.md file (Listing 1.13).

-rf flag, 36

rm command, 15t, 36

Git, branching

branch status, displaying, 43

current branch, identifying, 42

deleting branches, 44

editing branches, 42

listing branches, 42

merging results, 43-44

pushing changes up to the Bitbucket, 39

Git, installation and setup

adding messages to the commit, 35

commit command, 35, 43

commit messages, displaying, 35

committing changes, 35, 43

first-time repository, 34-35

first-time system, 33-34

.gitignore file, 34

log command, 35

-m flag, 35

overview, 33-35

staging area for files, 33

status command, 34

Git, repositories

backing up, 37

copies of. See Git, branching.

pushing changes up to, 39

setting up, 34-35

staging areas, 33

GitHub, 37

.gitignore file

adding Spring server (Listing 3.43), 140-141

displaying, 142

generating, 34

GitLab, 37

Googling error messages, 5

Goto Anything command, 93n

.gravatar_edit class (Listing 7.11), 317n

gravatar_for helper function (Listing 7.9), 315

Gravatars (globally recognized avatars) (Listings 7.8 to 7.9), 314-318

GREEN flag, 9

GREEN (passing) tests (Listings 3.17 to 3.22), 114-117

Guard program, 137-143

H

Haml template system, 126n13

Hansson, David Heinemeier, 3, 110n

Hash symbol (#)

comment indicator, 21

styling CSS IDs, 725

styling CSS IDs (Listing 5.9), 208

URL stub, 198

Hashed passwords (Listings 6.35 to 6.36), 286-289

Hashes

: (colon), as a hashkey, 171-172

{ } (curly braces), hash indicator, 171, 176

=> (equal, greater than), hashrocket, 171

versus arrays, 170-172

classes, 178

computational cost, 396

definition, 286

each method, 174

indices, 171

inspect method, 174-175

keys, 171

as last argument, 176

nested, 174

p function, 175

printing, 175

symbols as hash keys, 171-172

Hashing

versus encryption, 287n19

MD5 hashing algorithm, 314-315

options hash, 267

has_many associations

Relationship model (Listing 14.3), 689

toy application, 81-82, 82

has_many relationships (Listing 13.11), 608-611, 609

has_many :through association (Listings 14.8 to 14.10), 692-695

has_secure_password method, 286-289, 294

header tag, 197-198

Headers

partials for, 212-216

site layout, 197, 212-216

Hello world program

controller action (Listing 1.8), 28-31

creating a skeleton, 14

default page, 27

making a workspace directory (Listing 1.2), 14-18

MVC (Model-View-Controller) architecture, 26-27, 28

Rails router, editing, 29-30

root route (Listings 1.9 to 1.10), 29-30

root URL, 29-30

viewing in a browser, 31

Help, Rails Tutorial, 9

help action (Listings 3.6, 3.7, 3.10), 100, 104, 107

Help for Rules Tutorial, 7n

Help page

custom HTML (Listing 3.12), 108

Help pages

cleaned up views (Listings 3.36 to 3.38), 130-131

creating, 100-101, 104, 107

custom, sample, 109

custom HTML (Listing 3.11), 108

generated view (Listing 3.10), 107

with HTML structure removed (Listings 3.37 to 3.38), 130-131

refactored views (Listings 3.36 to 3.38), 130-131

Helpers. See specific helpers

Heroku

commands, 50-51

creating and configuring an account (Listing 1.15), 48

deployment, 48-50

deployment to, 361

heroku command, 48

heroku create command, 48

heroku open command, 49

PostgreSQL database, 46

renaming applications, 50

setup (Listings 1.14 to 1.15), 46-48

SSH key, adding, 48

heroku command, 48

heroku create command, 48

heroku open command, 49

Heroku Toolbelt, 48

hexdigest method, 314

Hidden fields, password reset (Listing 12.14), 581

Hierarchy, examining Static Pages controller, 185-187, 186

Hierarchy of classes, determining, 179-180

Highlighted lines in code samples, 9

home action, creating Home pages (Listings 3.6, 3.7), 100-104

Home page mockups

Bootstrap and custom CSS, 202-210, 206, 208, 211

CSS styling, 206

custom page, 109

with debug information, 306

footer, 215

form error, 643

form for creating microposts, 635, 642

with proto-feed, 644, 647

site logo (Listing 5.9), 209, 210

site navigation, 201

spacing, 206

typography, 208

without custom CSS, 200-202, 201

Home page mockups, following users

with follow statistics, 704

incremented followers count, 684

status feed, 684, 730, 739

Home pages. See also Site layout.

with account activation message, 538

adding microposts (Listing 13.37), 636-637

boot route, setting, 133

boot route, setting (Listing 3.41), 132-133

creating (Listings 3.6, 3.7), 100-104

custom HTML (Listing 3.11), 108

embedded Ruby title (Listings 3.31 to 3.40), 125-132

full HTML structure (Listings 3.26 to 3.30), 121-125

generated view (Listing 3.9), 107

link to the sign-up page (Listing 5.2), 196n

raw view, 105

with a title, 122

Home pages, follower statistics

adding (Listing 14.17), 703-704

styling (Listing 14.18), 704-705

HTML

doctype declarations (Listing 3.23), 120

document divisions, 197-198

document type (Listing 3.23), 120

header tag, 197-198

li: (list item) tag, 198

lists, 198

nav tag, 198-199

placing markup in a separate file. See Partials.

section tag, 198

selectors, 120

self-closing tags, 201n

structure of a typical web page (Listing 3.23), 120

testing for specific tags, 120

ul: (unordered list) tag, 198-199

whitespace sensitivity, 120, 198

HTML shims (Listings 5.12 to 5.13), 196, 212-213

html.erb file extension, 126

HTTP (Hypertext Transfer Protocol) remembering a user’s identity. See Sessions. stateless protocol, 366

HTTP request methods, 104-105. See also specific methods

I

IDE (integrated development environment). See Cloud9.

IDs, CSS, 198

if-else statement, 390

if-then statements, writing. See Ternary operator.

Images

for microposts. See CarrierWave uploader; Microposts, images.

representing users. See Gravatars.

setting alternative display of, 201-202

image_tag helper function

rendering images (Listing 13.62), 661-663

setting alternate images (Listing 5.2), 196n

Implicit return, functions, 160

Indentation, setting in Cloud9, 12, 12

index action

showing all users (Listings 10.34 to 10.40), 483-488

toy application (Listing 2.6), 68-69

index action redirect (Listing 10.34), 484-485

Index page, showing all users

adding the URL to the users link (Listing 10.40), 487

bootstrap-will_paginate method (Listings 10.44 to 10.46), 492-494

CSS for users index (Listing 10.39), 487

index action (Listings 10.34 to 10.40), 483-488

index action redirect (Listing 10.34), 484-485

index view (Listings 10.34 to 10.40), 485-486

overview, 483-488

paginate method (Listings 10.45 to 10.46), 493-494

pagination (Listings 10.45 to 10.46), 493-494, 495

partial refactoring (Listings 10.50 to 10.52), 498-499

requiring a logged_in_user before filter (Listing 10.35), 485

testing index action redirect (Listing 10.34), 484-485

testing pagination (Listings 10.47 to 10.48), 496-497, 495

will_paginate method (Listings 10.44 to 10.46), 492-494

Index page, toy application, 71-73, 79

Index page mockups, showing all users

basic page, 484

with one hundred users, 491

with one user, 489

with pagination, 495

Index pages, toy application, 61-65

Indexing arrays, 163

Indices, 171

Inheritance, 179-183, 182, 256

Inheritance hierarchies, toy application

ApplicationController class (Listing 2.22), 85-87, 86, 87

for controllers (Listings 2.20 to 2.21), 85-87, 86, 87

MicropostsController class (Listing 2.21), 86 for models (Listings 2.18 to 2.19), 85-87, 86, 87

overview, 85-87, 86, 87

schematic of, 86, 87

UsersController class (Listings 2.12, 2.20), 76-78, 86

Initialization hash, 257

Initializing objects, 257

inspect method, 174-175, 273

Inspecting cookies, 425n

Installing

Bootstrap, 204

Gemfile (Listing 1.4), 19-23

Git. See Git, installation and setup.

Rails on a local system (Listing 1.6), 23-24

Installing Rails on Cloud9

bundle command, 23n

Bundler, 18-23

command-line program, 23

default directory structure, 18t

gem command, 12-13

installing Gemfile (Listing 1.4), 19-23

opening a new terminal tab, 25

overview, 12-13

rails new command (Listing 1.3), 14-18

rails server (Listings 1.6 to 1.7), 23-25

sample directory structure, 17

script, 23

shortcuts, 101t

with a specific version number (Listings 1.1 to 1.5), 12-13

Instance methods, 179

Instance variables, creating, 188

Instances of classes, 179

Integrated development environment (IDE). See Cloud9.

Integration testing

account activation (Listing 11.33), 550-551

assertions (Listing 5.32), 236-238, 238t

Contact page (Listing 5.21), 228-230

for invalid sign-up submissions (Listing 7.23), 341-343

for layout links (Listing 5.32), 236-238

multiple assertions per test, 236n

for valid sign-up submissions (Listing 7.33), 355-356

“Invalid multibyte character” error message, 30n

Invalid session input, handling, 373-377

IP binding address, specifying and displaying, 23

$IP environment variable, specifying, 23

irb configuration (Listing 4.8), 151

Iteration over innumerable data structures. See Blocks.

J

join method, 165, 734

.js.erb files, 726

JS-ERB files, 726

K

Keys, 171

kill command, 143

L

Labels. See Symbols.

Lambda, 614

Launch School, 7

Layout. See Site layout.

Layout files (Listing 3.35), 128-129

Learn Enough Command Line to be Dangerous, 1

Learn Enough Git to be Dangerous, 32

Learn Enough Society, 6

Learn Enough Text Editor to be Dangerous, 41n

Length validation (Listing 2.13), 79-81

Less-than signs (<<), adding to arrays, 165

li: (list item) tag, 198-199

lib/assets directory, 218

Links. See also Site layout.

creating, 198

named routes, 227228t

stub URLs, 198

link_to helper function, 198

Listing. See also Displaying; Showing.

branches, 42

directory contents, 36

users, toy application, 61, 61, 61, 63, 66-67, 65

Lists, HTML, 198-199

Literal constructors, 178

Literal strings, 153

Local development environment, 10

Local servers

running. See rails server command.

sharing, 26

log command, 35

Logged in status, determining (Listings 8.18 to 8.20), 391-394

logged_in? method (Listing 8.18), 391-392

logged_in_user method

friendly forwarding (Listing 10.31), 480-481

Microposts controller (Listing 13.32), 632-633

requiring logged-in users (Listing 10.15), 467-473

Logging in. See also Remember me; Sessions.

changing layout links (Listings 8.18 to 8.20), 391-394

concerns technique, 382n

current user, finding (Listings 8.16 to 8.17), 389-390

current_user method (Listings 8.16 to 8.17), 389-390

find method (Listing 7.5), 386-389

find_by method (Listing 8.16), 386-389

logged in status, determining (Listings 8.18 to 8.20), 391-394

logged_in? method (Listings 8.18 to 8.20), 391-394

log_in method (Listings 8.14 to 8.15), 383-385

overview (Listing 8.13), 382-383

and redirecting to the profile page (Listing 8.15), 384-385

session method (Listings 8.14 to 8.15), 383-385

successful login mockup, 391

upon sign-up (Listings 8.25 to 8.27), 400-402

user profile mockup, 391

validating user login (Listings 8.23 to 8.24), 398-399

Logging in, testing layout changes

mockup, drop-down menu, 395

mockup, logged-in user, 395

overview, 395-400

Logging out

only if logged in (Listings 9.11 to 9.19), 428-433

overview (Listings 8.29 to 8.32), 403-405

from persistent sessions (Listing 9.12), 427

a test for logout (Listing 9.12), 427

Login form, code for (Listing 12.3), 569

Login form mockups

access failure, 468

drop-down menus (Listings 8.21 to 8.24), 395

a protected page, 468

“remember me” checkbox, 434, 436

successful login, 391

log_in method (Listings 8.14 to 8.15), 383-385

Login page with forgot password link, 567

Login versus remembering, account activation, and password reset, 516t

log_in_as method (Listing 9.23), 440-443

Logo. See Site logo.

log_out method (Listings 8.29 to 8.32), 403-405

lorem ipsum text, 301, 622n–623n

Lorem.sentence method (Listings 13.25 to 13.26), 622-626

Lovitt, Michael, 275n

ls command, 36

Ludowyk, Tristan, 593n

M

-m flag, 34

Magic columns, 252, 258

make utility. See Rake language.

Manifest files (Listing 5.194), 218-219

map method

blocks, 168

status feed, following-users page, 732-735

Mapping user URLs to

controller actions (Listing 2.5), toy application, 68, 65

correspondence between pages, 61t

Markdown markup language, 41

Markup, placing in a separate file. See Partials.

Mass assignment, 333-336

.md file extension, 41

MD5 hashing algorithm, 314-315

Memoization, 386n

Merging branches, 43-44

Message chaining, 157

Message passing, 156-159

Messages, adding to a commit, 35. See also Error messages; Sign-up error messages.

Metaprogramming, 541

Method definitions in the console, 159-161

Method reference convention, 284

Method reference technique, account activation, 521

Methods. See also Functions.

adding to built-in classes, 417-418

calling themselves. See Class methods.

versus functions, 156

remembering variable assignments. See Memoization.

Micropost controller (Listing 2.12), 7678

Micropost model. See also Showing microposts.

associations between models (Listings 13.10 to 13.12), 608-611

associations between models, summary of, 609t

basic model, 602-604

belongs_to relationships (Listings 11.9, 12.3, 13.10), 608-611

data model, 602

default scope (Listings 13.14 to 13.17), 612-615

default_scope method (Listing 13.17), 614

dependent: :destroy (Listings 13.19 to 13.20), 615-616

destroying users (Listings 13.19 to 13.20), 615-616

foreign key reference, 603n

generating (Listings 13.1 to 13.3), 602-604

has_many relationships (Listing 13.11), 608-611, 609

migration with added index (Listing 13.3), 604

multiple key index, 604

ordering posts (Listings 13.17), 614

overview, 601-602

validation (Listings 13.4 to 13.8), 605-608

Micropost model, mockups

Home page with a form error, 643

Home page with form for creating microposts, 635, 642

Home page with proto-feed, 644, 647

user profile page with code for microposts, 621

user profile page with microposts, 617, 625-626

user profile page with pagination links, 627

user profile page with unstyled microposts, 623

Micropost model, testing user profiles

associating fixture microposts with users (Listing 13.27), 628-629

micropost pagination, 625-627

profile structure (Listings 13.27 to 13.28), 627-630

Micropost page, toy application, 79

Micropost resource. See Toy application, Micropost resource.

Microposts

access control (Listings 13.31 to 13.34), 632-634

authorization tests for Micropost controller (Listings 13.31 to 13.34), 632-634

definition, 601

displaying. See Showing microposts.

feed. See Microposts, proto-feed.

logged_in_user method (Listing 13.32), 632-633

routes for the Micropost resource (Listing 13.30), 628t

samples. See Micropost model, mockups.

Microposts, creating

adding to the Home page (Listing 13.37), 636-637

create action (Listing 13.36), 635-636

creating (Listings 13.36 to 13.45), 635-642

form for creating microposts (Listing 13.37), 632

redefining error messages (Listings 13.41 to 13.45), 639-642

user info sidebar (Listing 13.38), 637

Microposts, destroying

adding a delete link (Listing 13.51), 650-652

destroy action, 650-652

HTTP_REFERER, 652n

request.referrer method, 652, 652n

Microposts, images. See also CarrierWave uploader.

adding to Micropost model (Listing 13.58), 658-659

basic uploading (Listings 13.59 to 13.62), 659-663

cloud storage, 672-674

display size, constraining, 668n

format validation (Listings 13.64 to 13.66), 664-667

image_tag helper (Listing 13.62), 661-663

picture attribute, 659, 660

resizing, 668-669

resizing (Listings 13.67 to 13.68), 667-670

size validation (Listings 13.65 to 13.66), 665-667

Microposts, mockups

Home page after deleting a micropost, 653

Home page with a new micropost, 648

Home page with a proto-feed, 643, 647

proto-feed with delete links, 650

Microposts, proto-feed

failed submissions, 648

@feed_items instance variable (Listings 13.47 to 13.50), 645-649

Home page with a proto-feed, 644

overview, 643-649

SQL injection, security hole, 645

status feed (Listings 13.48 to 13.49), 645-649

where method (Listing 13.46), 634-635

Microposts, testing

adding a micropost with a different owner (Listing 13.53), 653-654

deletion with user mismatch (Listing 13.54), 654-655

integration test for the micropost interface (Listing 13.55), 655-656

@microposts instance variable (Listing 13.23), 619

MicropostsController class (Listing 2.21), 86

Migrating down, 254

Migrating up, 252

Migration file name, 252

Migrations. See Database migration; Rake db:migrate command.

MiniMagick, CarrierWave (Listing 13.67), 669-670

MiniTest assertions, list of, 120n

MiniTest reporters, 136-137

minitest-reporters gem, 136

Missing page titles, 147

mkdir (create directory) command, 14-15t

Mockingbird, 194n, 300n

Mockups, tool for, 194n. See also specific mockups.

Model file, User model, 255-256

Modeling users. See User model.

Modification timestamp, updating, 116-117

Moses, Riley, 279n

Multiline blocks, 168

Multiple-key indices, 604, 687

Mutating arrays, 165

mv (move files) command, 14-15t

MVC (Model-View-Controller) architecture

controllers, 26-27

default Rails page, 27

flow diagram, 67

models, 26-27

requests, 26

schematic view, 28

sharing a local server, 26

toy application, 66-73

views, 26-27

N

Named constructors, 178

Named routes

in links, 227228t

in site layout (Listings 5.30 to 5.31), 233-235

Naming conventions

CamelCase, 100-101

scaffold command, 58n

scaffolding, 58n

snake case, 100-101

User model, 251

nav tag, 198-199

navbar class, 197

navbar-fixed-top class, 197

navbar-inverse class, 197

navbar-nav class, 198-199

Navigating

the filesystem, 93n

site layout, 195-202

Nested hashes, 174

Nesting Sass style sheets (Listing 5.7), 221-223

new action, creating a Sessions controller, 366-369

new method, as named constructor, 178

newline

in CSS (Cascading Style Sheets), 176

definition, 154

Nginx, 46

nil value

in a boolean context, 158

definition, 154

and the empty? method, 157

message chaining, 157

responding to methods, 157

testing for, 157-158

“Nothing at all” value. See nil value.

O

Objects

in the console, 156-159

converting to strings, 157

definition, 156

message passing, 156-159

Octothorpe. See Hash symbol (#), comment indicator.

ol (ordered list) tag, 618

Online resources. See also Books and publications.

Bloc, 6

Code School, 6

Firehose Project, 7

help, Rails Tutorial, 9

help for Rules Tutorial, 7n

Launch School, 7

Learn Enough Society, 6

Pragmatic Studio, 7

Rails Guides, 7

RailsApps, 7

RailsCasts, 7

Thinkful, 7

open command, 49

Opening new terminal tabs, 2425

Options hash, 267

Ordered list (ol) tag, 618

Ordering micropost posts (Listings 13.17), 614

Overwriting current changes, 36

P

p function, 174-175

paginate method (Listing 10.46), 494

Pagination

microposts, 619-621, 625-627, 626

showing all users (Listings 10.44 to 10.46), 492-494, 495

will_paginate method, 619-621

Palindromes, checking for, 180-183

params hash, sign-up failure (Listing 7.15), 332-333

params variable (Listing 7.1), 301

Parentheses ( () )

in statement syntax, 424n

and the ternary operator, 437n14

Partial refactoring (Listings 10.50 to 10.52), 498-499

Partials

for headers, 212-216

for HTML shims (Listings 5.12 to 5.13), 212-213

overview, 211-212

render helper function, 212-213

sharing across views, 212n

for site footer (Listings 5.15 to 5.17), 214-216

Passive relationships

model for, 696

Relationship model, 685-686

Relationship model (Listings 14.12 to 14.13), 695-697

Password reset. See also Forgot password form.

adding a link to (Listing 12.2), 566

adding password reset methods (Listings 12.5 to 12.6), 571-573

adding reset methods to the User model (Listing 12.52), 588

clearing the reset digest (Listing 12.22), 595

create action (Listings 12.5 to 12.6), 571-573

edit action (Listings 12.14 to 12.15), 581-583

expired resets, testing for (Listing 12.21), 594-595

form for, 584

form for (Listings 12.14 to 12.15), 581-583

generating a controller for (Listings 12.1 to 12.2), 565-566

hidden fields (Listing 12.14), 581

integration test (Listing 12.18), 590-591

login form, code for (Listing 12.3), 569

overview, 561-563

password reset view (Listing 12.4), 570

reset attributes, 568

resetting the password (Listings 12.14 to 12.15), 581-583

update action (Listings 12.16 to 12.17), 584-588

update_columns template (Listing 12.20), 593-594

User model, 568

Password reset, mockups

failed password reset, 589

forgot password form, 563, 570, 573, 578

forgot password link, 562

login page with forgot password link, 567

password reset form, 584

reset email, HTML version, 578

reset email, text version, 578

reset password form, 564

successful password reset, 589

Password reset mailer method

creating (Listing 12.7), 574-575

HTML email template (Listing 12.9), 575

mailing the password reset link (Listings 12.7 to 12.11), 574-577

plain-text email template (Listing 12.8), 575

sample reset email from the server log (Listing 12.11), 576-577

testing (Listing 12.12), 579-580

view templates, defining (Listings 12.8 to 12.9), 575

working preview method (Listing 12.10), 576

Password reset test

failed password reset, mockup, 589

integration test (Listing 12.18), 591-592

overview, 590-592

successful password reset, mockup, 589

Password reset view (Listing 12.4), 570

Password security

authentication, 293-296

bcrypt hash function (Listing 6.36), 288-289, 294n22

confirmation (Listings 6.37 to 6.40), 289-291

hash, definition, 286

hashed passwords (Listings 6.35 to 6.36), 286-289

hashing versus encryption, 287n19

minimum length (Listings 6.41 to 6.42), 291-293

overview, 286

password digest, 287. See also Hashed password.

salted hashed, 294n22

unencrypted passwords, 419n

User model, 288

virtual, definition, 287n18

virtual attributes, 287

Password test versus account activation, remembering, and login, 516t

password_confirmation attribute, 287

password_digest attribute (Listing 6.35), 287-288. See also Hashed passwords.

Password_reset method (Listings 12.7 to 12.11), 574-577

Passwords

allowing blank (Listing 10.13), 465

duplicates across users, 412

PATCH method, 104-105

Patterns of Enterprise Application Architecture (Fowler), 248n1

Permanent cookies, 417-425

permanent method, 417-425

Persistence, 249

Persistent sessions

creating, 410

logging out (Listing 9.12), 427

testing (Listing 9.31), 447

updating current_user (Listing 9.9), 424-425

Philips, Andy, 287n19

Phusion Passenger, 45-46

picture attribute, 659, 660

Pictures. See Images.

pid file will be overwritten, error message, 135n

pluralize text helper, 338

Plus operator (+), concatenating strings, 153

$PORT environment variable, 23

Port number, specifying and displaying, 23

POST method, 104-105

PostgreSQL database, 46-48

Pound sign. See Hash symbol (#), comment indicator.

Pragmatic Studio, 7

Preprocessor engines, 219-220

Printing

hashes, 174-175

strings, 154

private keyword, 334

Pro Git, 40n

Proc file, creating from a block, 614

Processes, displaying, 142-143

Production environments, 303

Profile page, successful account activation, 547

Programs that write other programs. See Metaprogramming.

Proto-feed

failed submissions, 648

@feed_items instance variable (Listings 13.47 to 13.50), 645-649

Home page with a proto-feed, 644

overview, 643-649

SQL injection, security hole, 645

status feed (Listings 13.48 to 13.49), 645-649

where method (Listing 13.46), 634-635

provide function, 126n14

ps command, 142-143

push method, adding to arrays, 165

Pushing changes up to Git repositories, 39

puts function, 154

Q

q command, 35

Query parameters, account activation, 528

Question mark (?)

boolean indicator, 156

in query parameters, 528

Quitting Git, 35

R

Rails

creator of, 3

definition, 4

environments, 302-306

learning Ruby first, 6

open source, 4

prerequisites, 5-7

shortcuts, 101t

“The Rails 3 Asset Pipeline in (about) 5 minutes” (Erasmus), 217n

Rails console. See Console.

Rails Guides, 7

rails new command (Listing 1.3), 14-18

Rails router, editing, 29-30

Rails routes (Listings 5.27 to 5.28), 230-233. See also Named routes; Root routes.

“Rails Routing from the Outside In,” 701n

rails server command (Listings 1.6 to 1.7). See also Installing Rails on Cloud9.

default RAILS page, 27

IP binding address, specifying and displaying, 23

$IP environment variable, 23

overview, 23-25

$PORT environment variable, 23

port number, specifying and displaying, 23

Rails Tutorial Cloud9 workspace, 10

Rails Tutorial help, 7n

RailsApps, 7

RailsCasts, 7

rake db:migrate command, 60

Rake language, definition, 60

Ranges, 163-167. See also Arrays.

Reading data from the web. See GET method.

README.md file (Listing 1.13, 3.3)

branching, 41-42

creating, 40-41

definition, 40

editing, 42

.md file extension, 41

merging with the master branch, 43-44

sample code, 96-97

README.md file (Listings 1.13, 3.3)

committing changes to, 43

pushing changes up to Bitbucket, 44-45

RecordNotFound exception, 260

Recursive force, deleting files and directories, 36

Red, Green, Refactor cycle, 113

RED flag, 9

RED (failing) tests (Listing 3.15), 113-114

redirect_back_or method (Listing 10.32), 481-482

Refactoring code

definition, 110

removing duplication (Listings 3.31 to 3.40), 125-132

smelly code, 117-118

Regex. See Regular expressions.

Regressions, 110-111

Regular expressions

Rubular tool, 275-277, 276

validating email addresses (Listing 6.21), 274-277, 275t

validating user data (Listing 6.21), 275-277, 275t

Relationship model. See Following users, Relationship model.

Remember branch, testing (Listings 9.21 to 9.23), 445-449

Remember me. See also Logging in.

cookies, 410

duplicate user passwords, 412

forget method (Listing 9.11), 426-427

overview, 409-410

persistent sessions, 410

“remember me” checkbox, 434, 436

remember_digest attribute (Listings 9.1 to 9.3), 411-415, 411t

remember_token method (Listing 9.3), 414-415

tokens (Listings 9.1 to 9.3), 410-415

Remember me, at login

authenticated? method (Listing 9.6), 420-421

authenticated? method (Listings 9.17 to 9.19), 431-433

overview, 417-425

persistent sessions (Listing 9.9), 424-425

remembering a logged-in user (Listings 9.7 to 9.9), 421-425

Remember me checkbox

creating (Listings 9.21 to 9.23), 433-438

CSS for (Listing 9.22), 435-436

login form mockups, 434, 436

testing (Listings 9.24 to 9.28), 440-445

remember me function, testing

collisions, checking for, 412n6

log_in_as method (Listing 9.24), 440-441

persistent sessions (Listing 9.31), 447

raising exceptions (Listing 9.29), 445-446

remember branch (Listings 9.21 to 9.23), 445-449

remember me checkbox (Listings 9.24 to 9.28), 440-444

remembering cookies (Listing 9.25), 442-443

removing raised exceptions (Listing 9.33), 448

remember_digest attribute (Listings 9.1 to 9.3), 411-415, 411t

Remembered options, 95n

Remembering cookies (Listing 9.25), 442-443

Remembering versus login, account activation and password reset, 516t

remember_token method (Listings 9.3), 414-415

Renaming applications, 50

render helper function, 212-213

Rendering images, in microposts (Listings 13.22 to 13.24, 13.62), 617-621, 661-663

Repositories. See Git, repositories.

request.referrer method, 652, 652n

Reset attributes, password reset, 568

Reset password form, 564

Resetting

databases. See Undoing, database migrations.

passwords. See Password reset.

Resizing micropost images (Listings 13.67 to 13.69), 667-670, 668-669

REST (REpresentational State Transfer), 70

RESTful routes

for the Micropost resource (Listing 13.30), 628, 629t

toy application, 71t, 76t

RESTful URLs, 308-309t

-rf flag, 36

rm command, 15t, 36

Root routes

adding (Listing 2.3), 56

defining (Listings 5.27 to 5.28), 230-231

definition (Listings 1.9 to 1.10), 29-30

setting (Listing 3.41), 132-133, 133

Root URL, 29-30

Routing. See Named routes; Rails routes; Root routes.

Rows, databases, 250

Rubular tool, 275-277, 276

Ruby language

classes. See Classes.

data structures. See Data structures.

make utility. See Rake language.

version numbers, displaying, 361-362

Ruby on Rails. See Rails.

Ruby on Rails Tutorial website, 2n

Rules (CSS), bundling and reusing. See Sass mixins (Listing 7.2).

S

S3 (Simple Storage Service), 672-674

Salted hashed passwords, 294n22

Sample applications. See Hello world program; Static pages; Toy application.

Sample data, creating

lorem ipsum text, 301, 622n–623n

Lorem.sentence method (Listings 13.25 to 13.26), 622-626

microposts (Listings 13.25 to 13.26), 622-626

users (Listing 10.43), 490-491

users (Listings 10.42 to 10.43), 491

Sandbox, for database migration, 256-257

Sass mixins (Listing 7.2), 304-306

Sass utility, alternate syntax, 220n

Sass utility, asset pipeline

asset directories, 218

definition, 218

manifest files (Listing 5.19), 218-219

preprocessor engines, 219-220

production efficiency, 220

Sass utility, style sheets (Listing 5.7). See also CSS (Cascading Style Sheets).

nesting, 221-223

overview, 220-221

variable names, 224

variables (Listings 5.8, 5.17), 223-227

save method, 257

Saving User objects to the database, 257

scaffold command

naming conventions, 58n

toy application, 58, 74-78

Scaffolding

description, 3-4

generate scaffold command, 3

Micropost resource, 74-78

naming conventions, 58n

scaffold command, 58

toy application, 53

.scss file extension, 205, 219-220

section tag, 197

Secure Sockets Layer (SSL). See SSL (Secure Sockets Layer).

Security, preventing unactivated users from logging in (Listing 11.32), 548. See also Authorization; Named routes; Password security.

Selecting array elements, 166

Selectors, 120

self keyword, 182-183

Self-closing tags, 201n

SendGrid, configuring (Listing 11.41, 12.23), 556-557, 595-597

Server computer, definition, 104-105

Server log errors, 308

Servers, sharing local, 26

Session hijacking, 358, 410, 412n5

session method (Listings 8.14 to 8.15), 383-385

Sessions. See also Logging in.

cookies, 366

definition, 366

destroying (Listings 8.29 to 8.32), 403-405

Sessions, creating

permanent. See Persistent sessions.

temporary (Listings 8.14 to 8.15), 383-385

Sessions, finding and authenticating users

authenticate method (Listing 8.7), 376, 377t

authenticating users (Listing 8.7), 376, 377t

failed login, mockup, 375

find_by method (Listing 8.7), 376

finding users (Listing 8.7), 376

invalid input, handling, 373-377

overview, 373-377

Sessions, flash

code for failed login (Listings 8.9 to 8.12), 379-382

flash test (Listings 8.9 to 8.12), 379-382

flash.now method (Listing 8.11), 381

rendering with a flash message (Listing 8.8), 377-379, 377t

Sessions, login form creation

code sample (Listing 8.4), 371

form_for helper, 371-372

form_tag helper, 371n

HTML sample (Listing 8.5), 373

mockup of completed form, 372

overview, 370-373

Sessions, login form mockups

added links, 372

basic form, 367

completed form, 372

with flash message, 378

flash persistence (Listings 8.9 to 8.12), 379-382

login failure, 370, 375, 378

Sessions, persistent

creating, 410

logging out (Listing 9.12), 427

testing (Listing 9.31), 447

updating current_user (Listing 9.9), 424-425

Sessions controller

adding resources (Listing 8.2), 368

overview, 366-369

routes, custom, 369t

routes, listing, 368-369

Setter methods, creating, 188

Shims (Listings 5.12 to 5.13), 196, 212-213

Shivs. See HTML shims.

Short-circuit evaluation, 388

Shortcuts, Rails commands, 101t. See also Ctrl-C keystroke; Ctrl-D keystroke.

Show page, mockups, 311

Showing all users. See also Displaying; Listing.

db/seeds.rb file (Listing 10.43), 490

Faker gem, adding to the Gemfile (Listing 10.42), 488-492

overview, 483

sample users, creating (Listing 10.43), 490-491

sample users, creating (Listings 10.42 to 10.43), 491

Showing all users, index page

adding the URL to the users link (Listing 10.40), 487

bootstrap-will_paginate method (Listings 10.44 to 10.46), 492-494

CSS for users index (Listing 10.39), 487

index action (Listings 10.34 to 10.40), 483-488

index action redirect (Listing 10.34), 484-485

index view (Listings 10.34 to 10.40), 485-486

overview, 483-488

paginate method (Listings 10.44 to 10.46), 492-494

pagination (Listings 10.44 to 4.46), 492-494

pagination (Listings 10.44 to 10.46), 495

partial refactoring (Listings 10.50 to 10.52), 498-499

requiring a logged_in_user before filter (Listing 10.35), 485

testing index action redirect (Listing 10.34), 484-485

testing pagination (Listings 10.47 to 10.48), 496-497, 495

will_paginate method (Listings 10.44 to 10.46), 492-494

Showing all users, index page mockups

basic page, 484

with one hundred users, 491

with one user, 489

with pagination, 495

Showing microposts. See also Micropost model.

count method, 620

counter cache, 620

@microposts instance variable (Listing 13.23), 619

number of posts per user, 620

paginating posts, 619-621

profile page with microposts, mockup, 617

rendering microposts (Listings 13.22 to 13.24), 617-621

time_ago_in_words method (Listing 13.22), 618-619

will_paginate method (Listing 13.24), 620-621

Side effects of functions, 154

Sidebar (Listings 7.10 to 7.11), 316-319

Signed cookies, 418

Signing up on Cloud9, 11

Sign-up, logging in (Listings 8.25 to 8.27), 400-402

Sign-up error messages

_error_messages.html.erb partial file (Listing 7.21), 337-338

any? method, 338

displaying (Listings 7.20 to 7.22), 336-340

empty? method, 338

error_explanation (Listing 7.22), 339-340

field_with_errors class (Listing 7.22), 339-340

mockups, 340

overview, 335-340

pluralize text helper, 338-339

styling with CSS (Listing 7.22), 339-340

testing, template for, 344

Sign-up failure

assert_select method, 342

attr_accessible method, 333

count method, 341

create action (listing 7.18), 329-332

debug information (Listing 7.18), 330-333

failure-page mockups, 331

mass assignment, 333-336

params hash (Listing 7.15), 332-333

private keyword, 334

strong parameters (Listing 7.19), 333-336

testing for invalid submissions (Listing 7.23), 341-343

testing for valid submissions (Listing 7.33), 355-356

a working form (Listing 7.18), 329-333

Sign-up forms

authenticity token, 328

CSRF (cross-site request forgery), 328

form tag, 328

form_for method, 320-324

mockups, 320-324, 321-322, 321-324, 324, 340

overview, 320

Sign-up forms, HTML

overview, 325-329

sample HTML (Listing 7.15), 325-327

Sign-up page

with account activation warning message, 548

adding an @user variable (Listing 7.14), 320-321

assigning a route (Listing 5.43), 242-244

custom stub view (Listing 5.46), 243

first user sign-up, 352-355, 352

flash messages (Listings 7.29 to 7.31), 349-351

linking a button (Listing 5.45), 242-244

linking to the Home page (Listing 5.2), 196n

Users controller, creating (Listings 5.38 to 5.39), 240-241

Sign-up page, mockups, 244, 249

filled-in form, 327

first user sign-up, 352

forms, 321-324

sign-up failure (Listing 7.18), 329-333, 330-331

Sign-up success

create action (Listing 7.28), 344-345

finished sign-up form, 346-348

finished sign-up form (Listing 7.22), 347

overview, 345-346

welcome message (Listings 7.29 to 7.31), 349-352

Sign-up test (Listing 11.33), 550-551

Simple Storage Service (S3), 672-674

Single quotes ('), mixing with double quotes, 136

Site layout. See also Bootstrap; Links.

alternate images, 200-201

document divisions, 198

footers (Listings 5.15 to 5.17), 214-216

headers, 197, 212-216

navigation, 195-202

site logo (Listing 5.9), 209

web page (Listings 3.31 to 3.40), 125-132

Site logo (Listing 5.9), 209

Site navigation

application.html.erb file (Listings 4.3, 5.1), 195-202

Home page mockup, 201

updating the site layout file (Listing 5.1), 195-202

Siwek, Katarzyna, 174-175

Size validation, micropost images (Listings 13.65 to 13.66), 665-667

Skeletons (code). See Scaffolding.

Slash (/)

root URL, 60

Unix directory separator, 8

Slash, asterisk (/* ... */), CSS comments, 205

Smelly code, 117-118

Snake case, 101

Spacing, Home page mockup, 206

split method, 163

spring command, 143

Spring process ID (pid) file will be overwritten, error message, 135n

Spring server

adding to .gitignore file (Listing 3.46), 140

preventing conflicts with Git, 139

SQL (Structured Query Language)

alternatives to. See Active Record.

case sensitivity, 614n

naming conventions, 614n

pronouncing “SQL,” 248n2

SQL injection, security hole, 645

SQLite Database Browser

pronouncing “SQLite,” 253

screen shots, 254, 255, 295

Square brackets ([]), accessing elements, 164

SSH key, adding to Heroku, 48

SSL (Secure Sockets Layer)

enabling, 358-359

in production deployment (Listing 7.36), 358-359

session hijacking, 358

SSL certificates, 359

Stabby lambda, 614

State, maintaining. See Cookies; Remember me.

Stateless protocol, 366

Static pages. See also About page; Contact page; Help page; Home page; Sign-up page.

boot route, setting, 133

boot route, setting (Listing 3.41), 132-133

custom pages (Listings 3.11), 108

embedded Ruby (Listings 3.31 to 3.40), 126-132

Gemfile (Listing 3.2), 94-95

generating (Listing 3.6), 100-107

generating a controller, 100-107. See also Static Pages controller.

generating a sample app (Listing 3.1), 94

help action (Listings 3.6, 3.7, 3.10), 100, 104, 107

layouts (Listings 3.31 to 3.40), 125-132

README file (Listing 3.3), 96-97

refactoring (Listings 3.31 to 3.40), 125-132

setup, 93-99

Static pages, dynamic titles

base titles, 147

on every page. See Base titles.

full_title helper function (Listings 4.2, 4.3, 4.11), 147-48, 162

HTML structure of a typical web page (Listing 3.23), 119

layout files (Listing 3.35), 128-129

list of sample pages, 119t

missing page titles, 147

overview, 118-119

RED testing, 119-121

templates for. See Embedded Ruby.

yield function, 126

Static Pages controller

code sample (Listing 3.6), 100

contents of config directory, 103

generating (Listing 3.6), 100-107

help action (Listings 3.6, 3.7, 3.10), 100, 104, 106-107

hierarchy, examining, 185-187, 186, 186

home action (Listings 3.6, 3.7), 100-104

Home page, generated view (Listing 3.9), 107

Home page, raw view, 105

Rails shortcuts, 101t

Static Pages controller, testing

default (Listing 3.13), 112-113

generating a test file (Listing 3.13), 112-113

GREEN (passing) tests (Listings 3.17 to 3.22), 114-117

Red, Green, Refactor cycle, 113

RED (failing) tests (Listing 3.15), 113-114

refactoring code, 117

status command, 34

Status feed

following-user mockups, 740

micropost (Listings 13.48 to 13.49), 645-649

Status feed, following-users page

initial status feed (Listing 14.44), 732-735

join method, 734

map method, 733

motivation and strategy (Listing 14.42), 731-732

sample, 730

subselects (Listings 14.45 to 14.47), 736-740

Stealing cookies, 410

String literals, 153

Strings

arrays of, 272

assigning values to, 153

assigning variable names to, 153

concatenating, 153

in the console, 153-155

converting from objects, 157

converting to arrays, 163

definition, 153

double-quoted, 153

interpolating, 153

printing, 154

single-quoted, 154-155

Strong parameters

create action (Listing 7.19), 334

deleting users (Listing 10.56), 504-505

sign-up failure (Listing 7.18), 330-333

Structured Query Language (SQL)

alternatives to. See Active Record.

pronouncing “SQL,” 248n2

Stub URLs, linking to, 198

Stub view for user information (Listing 7.4), 310

Style sheets, CSS (Listing 4.1), 175-177

Style sheets, Sass utility

nesting (Listing 5.7), 221-223

overview, 220-221

variable names, 224

variables (Listings 5.8, 5.17), 223-227

stylesheet_link_tag function, 146, 177

Styling with CSS (Listing 7.22), 339-340

Subselects (Listings 14.45 to 14.47), 736-740

Successful password reset, 589

superclass method, 179-180

Symbols

as hash keys, 171-172

overview, 172-175

T

Table attacks, protection from, 294n22

Tables

databases, 250

dropping from databases, 254

TDD (test-driven development), 110. See also Testing.

Technical sophistication, 1-2

Templates

testing error messages, 344

update_columns (Listing 12.20), 593-594

Templates for pages. See Embedded Ruby.

10 types of people, 438-439, 438-439

Ternary operator

in function return values, 439

and parentheses ( () ), 437n14

replacing assignment operators, 438-439

Test environments, 303

Test suites, 110

Testing. See also Integration testing; TDD (test-driven development).

About page, 114

authorization tests for Micropost controller (Listings 13.31 to 13.34), 632-634

authorizations, following users (Listing 14.24), 710-711

automated. See Automated testing.

commenting out failed tests (Listing 11.24), 537

a correct user (Listings 10.27 to 10.28), 476-478

destroyed users (Listings 10.60 to 10.62), 508-511

edits (Listings 10.20 to 10.21), 471-473

error messages, template for, 344

for expired password resets, (Listing 12.21), 594-595

failing tests, writing. See TDD (test-driven development).

for followers (Listing 14.13), 697

following relationships (Listing 14.40), 727-729

for friendly forwarding (Listings 10.29 to 10.32), 478-483

index action redirect (Listing 10.34), 484-485

logging in a test user (Listing 10.15), 468-471

logout (Listings 8.29 to 8.32), 404-405

logout (Listings 9.12), 427

MiniTest assertions, list of, 120-121

model tests. See Validating user data.

multiple assertions per test, 236n

for nil values, 157-158

pagination (Listings 10.44 to 10.46), 492-494, 495

password reset mailer method (Listing 12.12), 579-580

persistent sessions (Listing 9.31), 447

refactoring code, 110

regressions, 110-111

for specific HTML tags, 120

timing of, 110-111

unfollow buttons (Listing 14.40), 727-729

unsuccessful user updates (Listings 10.9), 461-462

the wrong user (Listing 10.24), 474

Testing, account activation

activation via user model object (Listing 11.37), 552-553

integration test (Listings 11.33 to 11.37), 550-551

overview, 549

sending email via user model object (Listing 11.36), 552

setting the test domain host (Listing 11.21), 535

user activation methods in the User model (Listing 11.35), 551-552

user sign-up test (Listing 11.33), 550-551

Testing, advanced

adding Spring to .gitignore file (Listing 3.4), 140

automated, 137-143

custom Guardfile (Listing 3.45), 138-139

file navigator, 140-141

Guard program, 137-143

MiniTest reporters, 136-137

Testing, Micropost user profiles

associating fixture microposts with users (Listing 13.27), 628-629

micropost pagination, 625-627

profile structure (Listings 13.27 to 13.28), 627-630

Testing, Static Pages controller

default (Listing 3.13), 112-113

generating a test file (Listing 3.13), 112-113

GREEN (passing) tests (Listings 3.17 to 3.22), 114-117

Red, Green, Refactor cycle, 113

RED (failing) tests (Listing 3.15), 113-114

refactoring code, 117

Text editors, aligning columns, 177n

Thinkful, 7

Thomas, Dave, 7

Time helpers, 418

time_ago_in_words method (Listing 13.22), 618-619

Timestamp on files and directories, updating, 116-117

Timestamps

database migrations, 252

User objects, 258n7

UTC (Coordinated Universal Time), 258n7

Titles on static pages

adding, 121-125

base titles, 147

on every page. See Base titles.

full_title helper function (Listings 4.2, 4.3, 4.11), 147-48, 162

HTML structure of a typical web page (Listing 3.24), 120

layout files (Listing 3.35), 128-129

list of sample pages, 119t

missing page titles, 147

overview, 118-119

templates for. See Embedded Ruby.

yield function, 126

Titles on static pages, testing

Home page title (Listing 4.4, 4.6), 148-149

page titles (Listings 3.23 to 3.25), 119-121

page titles (Listings 3.23, 3.24 to 3.25), 120-121

TLS (Transport Security Layer), 358n. See also SSL (Secure Sockets Layer).

to_a method, 166

Tokens (Listings 9.1 to 9.3), 410-415

Torvalds, Linus, 32

to_s method, 157

touch command, 116-117

Toy application

deploying, 88-89, 89

micropost data model, 57-58, 58

planning, 54-57

scaffolding, 53

updating the Gemfile (Listing 2.1), 54-55

user data model (Listing 2.6), 57-58, 57-58, 72. See also Toy application, Users resource.

Toy application, inheritance hierarchies

ApplicationController class (Listing 2.22), 85-87, 86, 87

for controllers (Listings 2.20 to 2.21), 85-87, 86, 87

MicropostsController class (Listing 2.21), 86

for models (Listings 2.18 to 2.19), 85-87, 86, 87

overview, 85-87, 86, 87

UsersController class (Listings 2.12, 2.20), 76-78, 86

Toy application, Micropost resource

data model associations (Listings 2.14, 2.15), 81-82, 82

data validation, 74

error messages, 80

first_user variable, 82

has_many associations, 81-82, 82

index page, 79

length validation (Listing 2.13), 79-81

Micropost controller (Listing 2.12), 7678

micropost page, 77

Rails console, 82

RESTful routes, 76t

scaffolding, 74-78

Toy application, Users resource

bundle exec, 60

controller actions (Listing 2.7), 69-70

correspondence between pages and URLs, 61t

creating users, 62-64, 62-63

destroying users, 64-66, 65

editing user information, 62, 63-64

index action (Listing 2.6), 68-69

index page, 60, 61, 71-73

listing users, 61, 61, 63, 66-67, 65

mapping user URLs to controller actions (Listing 2.5), 68, 65

migrating the database, 59-60

MVC (Model-View-Controller), 65-73

overview, 58-60

rake db:migrate command, 60

Rake language, 60

REST (REpresentational State Transfer), 70

RESTful routes, 71t

root route, adding (Listing 2.3), 56

scaffold command, 58

user page, 63

user pages, 61-65, 61-65

Users controller (Listing 2.7), 69-70

weaknesses, 74

Transport Security Layer (TLS), 358n. See also SSL (Secure Sockets Layer).

Tuite, Colm, 193n

Twitter-style relationships, 685

Typography (Listing 5.8), 208, 208-210, 209

U

uglifier gem, 21

ul: (unordered list) tag, 198

underscore method, 688n

Undoing

code generation, 102-103

database migrations, 102-103, 254, 256, 294n21

Unencrypted passwords, 419n

Unfollow buttons

mockups, 681-682, 709

testing (Listing 14.40), 727-729

Unfollowed user, mockup, 722

Uniform Resource Locator (URL), correspondence between pages, 61t

Uniqueness, email addresses

at the database level (Listings 6.29 to 6.34), 281-286

validating (Listings 6.23 to 6.34), 278-286

Unix command line

/ (forward slash), directory separator, 7

? (dollar sign), command line prompt, 8

cd (change directory) command, 14-15t

common commands, 15t

cp (copy files) command, 14-15t

mkdir (create directory) command, 14-15t

mv (move files) command, 14-15t

overview, 14

Unobtrusive JavaScript, 724

Unordered list (ul:) tag, 198

Unsuccessful sign-up. See Sign-up failure.

upcase method (Listing 6.26), 279

update action

password reset (Listings 12.16 to 12.17), 584-588

updating users (Listing 10.8), 459-460

updating users (Listings 10.11 to 10.13), 464-465

Updating

remote servers. See PATCH method.

User objects, 262-263

Updating a remote server. See PATCH method.

Updating users

adding a URL to the settings link (Listing 10.4), 456-457

edit action (Listings 10.1 to 10.4), 452-457

edit form (Listing 10.3), 455

edit form mockups, 455

edit view (Listing 10.2), 454

overview, 451

strong parameters (Listing 10.56), 504-505

update action (Listing 10.8), 459-460

Updating users, successful edits with TDD

acceptance tests, 463

allowing blank passwords (Listing 10.13), 465

overview, 462-466

successful mockup, 466

update action (Listings 10.11 to 10.13), 464-465

Updating users, unsuccessful edits

edit form mockup, 461

overview (Listing 10.8), 459-460

testing (Listing 10.9), 461-462

update action (Listing 10.8), 459-460

Uploading images

CarrierWave uploader (Listings 13.58 to 13.62), 657-663

CarrierWave uploader (Listings 13.69 to 13.71), 671-674

micropost (Listings 13.58 to 13.63), 657-663

URL (Uniform Resource Locator), correspondence between pages, 61t

url_encode method, 535n

User activation methods, testing (Listing 11.35), 551-552

User class (Listing 4.17), 187-190

User class inheritance, 256

User data, showing. See Displaying user data.

User email addresses, displaying, 310

User info sidebar (Listing 13.38), 637

User model. See also Databases.

with account activation attributes, 519

database migrations, 249-255

email addresses as user names, 250n

generating (Listing 6.1), 251

model file, 255-256

naming conventions, 251

overview, 248-249

persistence, 249

sample, 250, 253

sample code (Listing 6.3), 256

sketch of, 251

viewing the structure of, 253

User model, User objects

creating, 256-260

current date and time, 258

destroying, 259

finding, 260-261

initialization hash, 257

saving to the database, 257

timestamps, 258n7

updating, 262-263

validity. See Validating user data.

User names

displaying, 310

email addresses as, 250n

User objects

creating, 256-260

current date and time, 258

destroying, 260-261

finding, 260-261

initialization hash, 257

saving to the database, 257

timestamps, 258n7

User pages, toy application, 61-65, 61-65, 63

User profile page

adding a Users resource (Listing 7.3), 308

creating, 307-311

Gravatars (globally recognized avatars) (Listings 7.8 to 7.9), 314-318

logging in, mockup, 391

mockups, 300

RESTful URLs, 308-309t

routing, 307-309t

server log errors, 308

sidebar (Listings 7.10 to 7.11), 316-319

stub view for user information (Listing 7.4), 310

test for valid submission (Listing 7.33), 355-356

User profile page mockups

basic page, 301

code for microposts, 621

CSS, 322324

CSS (Listing 7.11), 317-319, 318

custom Gravatar, 315317

default Gravatar, 315316

with microposts, 617, 625-626

with pagination links, 627

sidebar, 318

unfollow button, 709

with unstyled microposts, 623

User profile page mockups, following-users

basic page, 680

finding a user to follow, 681

follow button, 681-682, 708

incremented followers count, 681-682

unfollow button, 681-682, 709

User sign-up test (Listing 11.33), 550-551

user.followers method (Listings 14.12 to 14.13), 695-697

user.following method (Listings 14.8 to 14.10), 692-695

user.forget method (Listing 9.11), 426-427

Userid, storing in cookies, 418-419

Users

adding to the fixture file (Listings 10.23 to 10.28), 473-478

deleting. See Deleting, users.

displaying. See Showing all users.

editing. See Updating users.

updating. See Updating users.

validating. See Validating user data.

Users controller

creating a sign-up page (Listings 5.38 to 5.39), 240-241

with a show action (Listing 7.5), 310

toy application (Listing 2.7), 69-70

Users index with delete links, mockup, 501

Users resource, adding to a user profile page (Listing 7.3), 308. See also Toy application, Users resource.

UsersController class (Listings 2.12, 2.20), 76-78, 86

UTC (Coordinated Universal Time), 258n7

V

valid? method, 257

Validating

images, CarrierWave uploader (Listings 13.64 to 13.66), 664-667

Micropost models (Listings 13.4 to 13.8), 605-608

Relationship model (Listings 14.4 to 14.5), 690-691

user login (Listings 8.23 to 8.24), 398-399

Validating user data

case sensitivity (Listings 6.26 to 6.27), 279-280

email addresses (Listings 6.18 to 6.23), 272-277

format (Listings 6.18 to 6.21), 272-277

length (Listings 6.14, 6.16), 269-271

options hash, 267

overview, 263-264

presence (Listings 6.7 to 6.12), 266-269

with regular expressions (Listing 6.21), 275-277, 275t

validity testing (Listings 6.4 to 6.5), 264-265

Variable names, Sass style sheets, 224

Variables, Sass style sheets (Listings 5.8, 5.17), 223-227

vendor/assets directory, 218

Version control

application source code. See Git.

definition, 32

specifying a version range (Listings 1.1 to 1.5), 12-13

Vertical bars (||)

block variable indicator, 168

or operator, 157

Vertical bars, equal sign (||=), or equals

assignment operator, 387-388

Vertical dots in code listings, 9

Views

cleaned up (Listings 3.36 to 3.38), 130-131

corresponding actions (Listings 3.9, 3.10), 107

embedded Ruby (Listings 3.31 to 3.40), 125-132

full_title helper function (Listings 4.2, 4.3, 4.11), 147-48, 162

Virtual attributes, 287

Visscher, Sjoerd, 196n

w[ ] technique, 272

WEBrick webserver, 359

where method (Listing 13.46), 634-635

Whitespace sensitivity, HTML, 120, 196n

will_paginate method

showing all users (Listings 10.44 to 10.46), 492-494

showing microposts (Listing 13.24), 620-621

Wireframes. See Mockups.

—without production option, 95

Workspaces

creating on Cloud9, 11, 12

Rails Tutorial Cloud9, 10

Y

YAML (YAML Ain’t Markup Language), 305n

yield method, 126, 198

You have not declared a Ruby version, error message, 361

Z

Zero-offset arrays, 163

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

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