100% found this document useful (1 vote)
6 views

Agile Web Development with Rails 4 4th Revised edition Edition Sam Ruby pdf download

The document provides information about the 4th Revised edition of 'Agile Web Development with Rails 4' by Sam Ruby, which serves as a comprehensive guide for building web applications using Ruby on Rails. It includes praise from notable figures in the Ruby community and details about the book's content, structure, and various topics covered. Additionally, it offers links to download the book and other related resources.

Uploaded by

lovenegjymi65
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
6 views

Agile Web Development with Rails 4 4th Revised edition Edition Sam Ruby pdf download

The document provides information about the 4th Revised edition of 'Agile Web Development with Rails 4' by Sam Ruby, which serves as a comprehensive guide for building web applications using Ruby on Rails. It includes praise from notable figures in the Ruby community and details about the book's content, structure, and various topics covered. Additionally, it offers links to download the book and other related resources.

Uploaded by

lovenegjymi65
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Agile Web Development with Rails 4 4th Revised

edition Edition Sam Ruby pdf download

https://ebookfinal.com/download/agile-web-development-with-
rails-4-4th-revised-edition-edition-sam-ruby/

Explore and download more ebooks or textbooks


at ebookfinal.com
We have selected some products that you may be interested in
Click the link to download now or visit ebookfinal.com
for more options!.

Agile Web Development with Rails 7 2nd Edition Sam Ruby

https://ebookfinal.com/download/agile-web-development-with-
rails-7-2nd-edition-sam-ruby/

Agile web development with rails a Pragmatic guide 1st


Edition Dave Thomas

https://ebookfinal.com/download/agile-web-development-with-rails-a-
pragmatic-guide-1st-edition-dave-thomas/

Continuous Testing with Ruby Rails and JavaScript 1st


Edition Ben Rady

https://ebookfinal.com/download/continuous-testing-with-ruby-rails-
and-javascript-1st-edition-ben-rady/

Web Development with Bootstrap 4 and Angular 2 2nd Edition


Sergey Akopkokhyants

https://ebookfinal.com/download/web-development-with-bootstrap-4-and-
angular-2-2nd-edition-sergey-akopkokhyants/
Web Application Development with Yii and PHP 2nd Revised
ed. Edition Jeffrey Winesett

https://ebookfinal.com/download/web-application-development-with-yii-
and-php-2nd-revised-ed-edition-jeffrey-winesett/

Ruby On Rails 3 Tutorial 1st Edition Michael Hartl

https://ebookfinal.com/download/ruby-on-rails-3-tutorial-1st-edition-
michael-hartl/

Murach s ASP NET 4 Web programming with C 2010 4th ed


Edition Boehm

https://ebookfinal.com/download/murach-s-asp-net-4-web-programming-
with-c-2010-4th-ed-edition-boehm/

Pro Agile NET Development with SCRUM 1st Edition Scott


Millett

https://ebookfinal.com/download/pro-agile-net-development-with-
scrum-1st-edition-scott-millett/

Node js Web Development 3rd revised Edition David Herron

https://ebookfinal.com/download/node-js-web-development-3rd-revised-
edition-david-herron/
Agile Web Development with Rails 4 4th Revised edition
Edition Sam Ruby Digital Instant Download
Author(s): Sam Ruby, Dave Thomas, David Heinemeier Hansson
ISBN(s): 9781937785567, 1937785564
Edition: 4th Revised edition
File Details: PDF, 12.32 MB
Year: 2013
Language: english
Early praise for Agile Web Development with Rails 4

Agile Web Development with Rails is the Rails way to build real-world web apps—it’s
definitive. Rails itself relies on this book as a test suite. Rails moves fast and
AWDwR is always there, a backstage pass to the very latest.

➤ Jeremy Kemper
Member of the Rails core team

This is an excellent way to quickly get up and running with Ruby and Rails. The
book is so good that Sam Ruby should change his name to Sam Rails.

➤ Aaron Patterson
Member of the Ruby and Rails core teams

Like many, I started out with Ruby by reading an earlier version of Agile Web
Development with Rails. Many years (and a few updates) later, it’s still as good a
resource for learning Rails as it has ever been, and this edition brings it right up
to date with Rails 4.

➤ Stephen Orr
Lead developer, Made Media
Agile Web Development with Rails 4

Sam Ruby
Dave Thomas
David Heinemeier Hansson

The Pragmatic Bookshelf


Dallas, Texas • Raleigh, North Carolina
Many of the designations used by manufacturers and sellers to distinguish their products
are claimed as trademarks. Where those designations appear in this book, and The Pragmatic
Programmers, LLC was aware of a trademark claim, the designations have been printed in
initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer,
Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade-
marks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes
no responsibility for errors or omissions, or for damages that may result from the use of
information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create
better software and have more fun. For more information, as well as the latest Pragmatic
titles, please visit us at http://pragprog.com.

The team that produced this book includes:


Susannah Pfalzer (editor)
Kim Wimpsett (copyeditor)
David J Kelly (typesetter)
Janet Furlow (producer)
Juliet Benda (rights)
Ellie Callahan (support)

Copyright © 2013 Pragmatic Programmers, LLC.


All rights reserved.

No part of this publication may be reproduced, stored in a retrieval system, or


transmitted, in any form, or by any means, electronic, mechanical, photocopying,
recording, or otherwise, without the prior consent of the publisher.

Printed in the United States of America.


ISBN-13: 978-1-937785-56-7
Printed on acid-free paper.
Book version: P1.0—September 2013
Contents
Acknowledgments . . . . . . . . . . . ix

Introduction . . . . . . . . . . . . xi

Part I — Getting Started


1. Installing Rails . . . . . . . . . . . . 3
1.1 Installing on Windows 4
1.2 Installing on Mac OS X 4
1.3 Installing on Linux 6
1.4 Choosing a Rails Version 8
1.5 Setting Up Your Development Environment 9
1.6 Rails and Databases 12

2. Instant Gratification . . . . . . . . . . 15
2.1 Creating a New Application 15
2.2 Hello, Rails! 17
2.3 Linking Pages Together 24

3. The Architecture of Rails Applications . . . . . . 29


3.1 Models, Views, and Controllers 29
3.2 Rails Model Support 32
3.3 Action Pack: The View and Controller 34

4. Introduction to Ruby . . . . . . . . . . 37
4.1 Ruby Is an Object-Oriented Language 37
4.2 Data Types 39
4.3 Logic 43
4.4 Organizing Structures 45
4.5 Marshaling Objects 48
4.6 Pulling It All Together 49
4.7 Ruby Idioms 50
Contents • vi

Part II — Building an Application


5. The Depot Application . . . . . . . . . . 55
5.1 Incremental Development 55
5.2 What Depot Does 56
5.3 Let’s Code 60

6. Task A: Creating the Application . . . . . . . 61


6.1 Iteration A1: Creating the Products Maintenance
Application 61
6.2 Iteration A2: Making Prettier Listings 68

7. Task B: Validation and Unit Testing . . . . . . 77


7.1 Iteration B1: Validating! 77
7.2 Iteration B2: Unit Testing of Models 82

8. Task C: Catalog Display . . . . . . . . . 91


8.1 Iteration C1: Creating the Catalog Listing 91
8.2 Iteration C2: Adding a Page Layout 96
8.3 Iteration C3: Using a Helper to Format the Price 100
8.4 Iteration C4: Functional Testing of Controllers 101
8.5 Iteration C5: Caching of Partial Results 104

9. Task D: Cart Creation . . . . . . . . . 107


9.1 Iteration D1: Finding a Cart 107
9.2 Iteration D2: Connecting Products to Carts 108
9.3 Iteration D3: Adding a Button 110

10. Task E: A Smarter Cart . . . . . . . . . 119


10.1 Iteration E1: Creating a Smarter Cart 119
10.2 Iteration E2: Handling Errors 124
10.3 Iteration E3: Finishing the Cart 128

11. Task F: Add a Dash of Ajax . . . . . . . . 135


11.1 Iteration F1: Moving the Cart 136
11.2 Iteration F2: Creating an Ajax-Based Cart 142
11.3 Iteration F3: Highlighting Changes 146
11.4 Iteration F4: Hiding an Empty Cart 149
11.5 Iteration F5: Making Images Clickable 152
11.6 Testing Ajax Changes 154
Contents • vii

12. Task G: Check Out! . . . . . . . . . . 159


12.1 Iteration G1: Capturing an Order 159
12.2 Iteration G2: Atom Feeds 172

13. Task H: Sending Mail . . . . . . . . . . 177


13.1 Iteration H1: Sending Confirmation Emails 177
13.2 Iteration H2: Integration Testing of Applications 184

14. Task I: Logging In . . . . . . . . . . 191


14.1 Iteration I1: Adding Users 191
14.2 Iteration I2: Authenticating Users 197
14.3 Iteration I3: Limiting Access 202
14.4 Iteration I4: Adding a Sidebar, More Administration 204

15. Task J: Internationalization . . . . . . . . 211


15.1 Iteration J1: Selecting the Locale 211
15.2 Iteration J2: Translating the Storefront 215
15.3 Iteration J3: Translating Checkout 222
15.4 Iteration J4: Add a Locale Switcher 229

16. Task K: Deployment and Production . . . . . . 233


16.1 Iteration K1: Deploying with Phusion Passenger and
MySQL 234
16.2 Iteration K2: Deploying Remotely with Capistrano 242
16.3 Iteration K3: Checking Up on a Deployed Application 248

17. Depot Retrospective . . . . . . . . . . 253


17.1 Rails Concepts 253
17.2 Documenting What We Have Done 256

Part III — Rails in Depth


18. Finding Your Way Around Rails . . . . . . . 261
18.1 Where Things Go 261
18.2 Naming Conventions 270

19. Active Record . . . . . . . . . . . 275


19.1 Defining Your Data 275
19.2 Locating and Traversing Records 280
19.3 Creating, Reading, Updating, and Deleting (CRUD) 284
19.4 Participating in the Monitoring Process 298
19.5 Transactions 304
Contents • viii

20. Action Dispatch and Action Controller . . . . . 309


20.1 Dispatching Requests to Controllers 309
20.2 Processing of Requests 319
20.3 Objects and Operations That Span Requests 330

21. Action View . . . . . . . . . . . . 341


21.1 Using Templates 341
21.2 Generating Forms 343
21.3 Processing Forms 346
21.4 Uploading Files to Rails Applications 348
21.5 Using Helpers 351
21.6 Reducing Maintenance with Layouts and Partials 358

22. Migrations . . . . . . . . . . . . 367


22.1 Creating and Running Migrations 367
22.2 Anatomy of a Migration 370
22.3 Managing Tables 375
22.4 Advanced Migrations 379
22.5 When Migrations Go Bad 382
22.6 Schema Manipulation Outside Migrations 383

23. Nonbrowser Applications . . . . . . . . . 385


23.1 A Stand-Alone Application Using Active Record 385
23.2 A Library Function Using Active Support 386

24. Rails’ Dependencies . . . . . . . . . . 393


24.1 Generating XML with Builder 393
24.2 Generating HTML with ERB 395
24.3 Managing Dependencies with Bundler 397
24.4 Interfacing with the Web Server with Rack 400
24.5 Automating Tasks with Rake 404
24.6 Survey of Rails’ Dependencies 405

25. Rails Plugins . . . . . . . . . . . . 411


25.1 Credit Card Processing with Active Merchant 411
25.2 Beautifying Our Markup with Haml 413
25.3 Pagination 416
25.4 Finding More at RailsPlugins.org 418

26. Where to Go from Here . . . . . . . . . 421

A1. Bibliography . . . . . . . . . . . . 423

Index . . . . . . . . . . . . . 425
Acknowledgments
Rails is constantly evolving and, as it does, so has this book. Parts of the
Depot application were rewritten several times, and all of the narrative was
updated. The avoidance of features as they become deprecated have repeat-
edly changed the structure of the book as what was once hot became just
lukewarm.

So, this book would not exist without a massive amount of help from the
Ruby and Rails communities. To start with, we had a number of incredibly
helpful formal reviewers of drafts of this book.

Jeremy Anderson Andrea Barisone Ken Coar


Jeff Cohen Joel Clermont Geoff Drake
Jeremy Frens Pavan Gorakavi Michael Jurewitz
Mikel Lindsaar Nigel Lowry Stephen Orr
Aaron Patterson Paul Rayner Martijn Reuvers
Doug Rhoten Gary Sherman Tibor Simic
Gianluigi Spagnuolo Davanum Srinivas Charley Stran
Federico Tomassetti Stefan Turalski José Valim

Additionally, each edition of this book has been released as a beta book:
early versions were posted as PDFs, and people made comments online. And
comment they did; over time more than 1,000 suggestions and bug reports
were posted. The vast majority ended up being incorporated, making this
book immeasurably more useful than it would have been. While thanks go
out to all for supporting the beta book program and for contributing so much
valuable feedback, a number of contributors went well beyond the call of
duty.

Manuel E. Vidaurre Arenas Seth Arnold


Will Bowlin Andy Brice
Jason Catena Victor Marius Costan

report erratum • discuss


Acknowledgments • x

David Hadley Jason Holloway


David Kapp Trung LE
Kristian Riiber Mandrup mltsy
Steve Nicholson Jim Puls
Johnathan Ritzi Leonel S
Kim Shrier Don Smith
Joe Straitiff Martin Zoller

Finally, the Rails core team has been incredibly helpful, answering questions,
checking out code fragments, and fixing bugs—even to the point where part
of the release process includes verifying that new releases of Rails don’t break
the examples provided in this book.1 A big “thank you” to the following:

Rafael França (rafaelfranca) Guillermo Iguaran (guilleiguaran)


Jeremy Kemper (bitsweat) Yehuda Katz (wycats)
Michael Koziarski (nzkoz) Santiago Pastorino (spastorino)
Aaron Patterson José Valim (josevalim)

Sam Ruby
rubys@intertwingly.net
August 2013

1. https://github.com/rails/rails/blob/master/RELEASING_RAILS.rdoc#is-sam-ruby-
happy--if-not-make-him-happy

report erratum • discuss


Introduction
Ruby on Rails is a framework that makes it easier to develop, deploy, and
maintain web applications. During the months that followed its initial release,
Rails went from being an unknown toy to being a worldwide phenomenon;
more important, it has become the framework of choice for the implementation
of a wide range of so-called Web 2.0 applications.

Why is that?

Rails Simply Feels Right


A large number of developers were frustrated with the technologies they were
using to create web applications. It didn’t seem to matter whether they used
Java, PHP, or .NET—there was a growing sense that their jobs were just too
damn hard. And then, suddenly, along came Rails, and Rails was easier.

But easy on its own doesn’t cut it. We’re talking about professional developers
writing real-world websites. They wanted to feel that the applications they
were developing would stand the test of time—that they were designed and
implemented using modern, professional techniques. So, these developers
dug into Rails and discovered it wasn’t just a tool for hacking out sites.

For example, all Rails applications are implemented using the Model-View-
Controller (MVC) architecture. Java developers are used to frameworks such
as Tapestry and Struts, which are based on MVC. But Rails takes MVC further:
when you develop in Rails, you start with a working application, there’s a
place for each piece of code, and all the pieces of your application interact in
a standard way.

Professional programmers write tests. And again, Rails delivers. All Rails
applications have testing support baked right in. As you add functionality to
the code, Rails automatically creates test stubs for that functionality. The
framework makes it easy to test applications, and as a result, Rails applica-
tions tend to get tested.

report erratum • discuss


Introduction • xii

Rails applications are written in Ruby, a modern, object-oriented scripting


language. Ruby is concise without being unintelligibly terse—you can express
ideas naturally and cleanly in Ruby code. This leads to programs that are
easy to write and (just as important) are easy to read months later.

Rails takes Ruby to the limit, extending it in novel ways that make a program-
mer’s life easier. This makes our programs shorter and more readable. It also
allows us to perform tasks that would normally be done in external configu-
ration files inside the codebase instead. This makes it far easier to see what’s
happening. The following code defines the model class for a project. Don’t
worry about the details for now. Instead, just think about how much informa-
tion is being expressed in a few lines of code.
class Project < ActiveRecord::Base
belongs_to :portfolio
has_one :project_manager
has_many :milestones
has_many :deliverables, through: milestones
validates :name, :description, presence: true
validates :non_disclosure_agreement, acceptance: true
validates :short_name, uniqueness: true
end

Two other philosophical underpinnings keep Rails code short and readable:
DRY and convention over configuration. DRY stands for don’t repeat yourself.
Every piece of knowledge in a system should be expressed in just one place.
Rails uses the power of Ruby to bring that to life. You’ll find very little dupli-
cation in a Rails application; you say what you need to say in one place—a
place often suggested by the conventions of the MVC architecture—and then
move on. For programmers used to other web frameworks, where a simple
change to the schema could involve a dozen or more code changes, this was
a revelation.

Convention over configuration is crucial, too. It means that Rails has sensible
defaults for just about every aspect of knitting together your application.
Follow the conventions, and you can write a Rails application using less code
than a typical Java web application uses in XML configuration. If you need
to override the conventions, Rails makes that easy, too.

Developers coming to Rails found something else, too. Rails doesn’t merely
play catch-up with the de facto web standards; it helps define them. And
Rails makes it easy for developers to integrate features such as Ajax and
RESTful interfaces into their code because support is built in. (And if you’re
not familiar with Ajax and REST interfaces, never fear—we’ll explain them
later in the book.)

report erratum • discuss


Introduction • xiii

Developers are worried about deployment too. They found that with Rails you
can deploy successive releases of your application to any number of servers
with a single command (and roll them back equally easily should the release
prove to be somewhat less than perfect).

Rails was extracted from a real-world, commercial application. It turns out


that the best way to create a framework is to find the central themes in a
specific application and then bottle them up in a generic foundation of code.
When you’re developing your Rails application, you’re starting with half of a
really good application already in place.

But there’s something else to Rails—something that’s hard to describe.


Somehow, it just feels right. Of course, you’ll have to take our word for that
until you write some Rails applications for yourself (which should be in the
next forty-five minutes or so…). That’s what this book is all about.

Rails Is Agile
The title of this book is Agile Web Development with Rails 4. You may be
surprised to discover that we don’t have explicit sections on applying agile
practices X, Y, and Z to Rails coding.

The reason is both simple and subtle. Agility is part of the fabric of Rails.

Let’s look at the values expressed in the Agile Manifesto as a set of four
preferences.1

• Individuals and interactions over processes and tools


• Working software over comprehensive documentation
• Customer collaboration over contract negotiation
• Responding to change over following a plan

Rails is all about individuals and interactions. There are no heavy toolsets,
no complex configurations, and no elaborate processes. There are just small
groups of developers, their favorite editors, and chunks of Ruby code. This
leads to transparency; what the developers do is reflected immediately in
what the customer sees. It’s an intrinsically interactive process.

Rails doesn’t denounce documentation. Rails makes it trivially easy to create


HTML documentation for your entire codebase. But the Rails development
process isn’t driven by documents. You won’t find 500-page specifications at
the heart of a Rails project. Instead, you’ll find a group of users and developers

1. http://agilemanifesto.org/. Dave Thomas was one of the seventeen authors of this


document.

report erratum • discuss


Introduction • xiv

jointly exploring their need and the possible ways of answering that need.
You’ll find solutions that change as both the developers and the users become
more experienced with the problems they’re trying to solve. You’ll find a
framework that delivers working software early in the development cycle. This
software may be rough around the edges, but it lets the users start to get a
glimpse of what you’ll be delivering.

In this way, Rails encourages customer collaboration. When customers see


just how quickly a Rails project can respond to change, they start to trust
that the team can deliver what’s required, not just what has been requested.
Confrontations are replaced by “What if?” sessions.

That’s all tied to the idea of being able to respond to change. The strong,
almost obsessive, way that Rails honors the DRY principle means that changes
to Rails applications impact a lot less code than the same changes would in
other frameworks. And since Rails applications are written in Ruby, where
concepts can be expressed accurately and concisely, changes tend to be
localized and easy to write. The deep emphasis on both unit and functional
testing, along with support for test fixtures and stubs during testing, gives
developers the safety net they need when making those changes. With a good
set of tests in place, changes are less nerve-racking.

Rather than constantly trying to tie Rails processes to the agile principles,
we’ve decided to let the framework speak for itself. As you read through the
tutorial chapters, try to imagine yourself developing web applications this
way, working alongside your customers and jointly determining priorities and
solutions to problems. Then, as you read the more advanced concepts that
follow in Part III, see how the underlying structure of Rails can enable you to
meet your customers’ needs faster and with less ceremony.

One last point about agility and Rails is that although it’s probably unprofes-
sional to mention this, think how much fun the coding will be!

Who This Book Is For


This book is for programmers looking to build and deploy web-based applica-
tions. This includes application programmers who are new to Rails (and
perhaps even new to Ruby) and ones who are familiar with the basics but
want a more in-depth understanding of Rails.

We presume some familiarity with HTML, Cascading Style Sheets (CSS), and
JavaScript, in other words, the ability to view source on web pages. You need
not be an expert on these subjects; the most you will be expected to do is to
copy and paste material from the book, all of which can be downloaded.

report erratum • discuss


Introduction • xv

How to Read This Book


The first part of this book makes sure you are ready. By the time you are
done with it, you will have been introduced to Ruby (the language), you will
have been exposed to an overview of Rails, you will have Ruby and Rails
installed, and you will have verified the installation with a simple example.

The next part takes you through the concepts behind Rails via an extended
example; we build a simple online store. It doesn’t take you one by one through
each component of Rails (“here is a chapter on models, here is a chapter on
views,” and so forth). These components are designed to work together, and
each chapter in this section tackles a specific set of related tasks that involve
a number of these components working together.

Most folks seem to enjoy building the application along with the book. If you
don’t want to do all that typing, you can cheat and download the source code
(a compressed tar archive or a zip file).2 This download contains separate sets
of source code for Rails 3.0, Rails 3.1, Rails 3.2, and Rails 4.0. As you will be
using Rails 4.0, the files you want are in the rails40 directory. See the README-
FIRST file for more details.

Be careful if you ever choose to copy files directly from the download into your
application, as the server won’t know that it needs to pick up these changes
if the timestamps on the file are old. You can update the timestamps using
the touch command on either Mac OS X or Linux, or you can edit the file and
save it. Alternately, you can restart your Rails server.

Part III, Rails in Depth, on page 259 surveys the entire Rails ecosystem. This
starts with the functions and facilities of Rails that you will now be familiar
with. It then covers a number of key dependencies that the Rails framework
makes use of that contribute directly to the overall functionality that the Rails
framework delivers. Finally, there is a survey of a number of popular plugins
that augment the Rails framework and make Rails an open ecosystem rather
than merely a framework.

Along the way, you’ll see various conventions we’ve adopted.

Ruby Tips
Although you need to know Ruby to write Rails applications, we realize
that many folks reading this book will be learning both Ruby and Rails
at the same time. You will find a (very) brief introduction to the Ruby
language in Chapter 4, Introduction to Ruby, on page 37. When we use a

2. http://pragprog.com/titles/rails4/source_code has the links for the downloads.

report erratum • discuss


Introduction • xvi

Ruby-specific construct for the first time, we’ll cross-reference it to that


chapter.

For example, this paragraph contains a gratuitous use of :name, a Ruby


:name symbol. In formats that support margins, you’ll see a reference to where
↪ on page 38
symbols are explained.

Live Code
Most of the code snippets we show come from full-length, running exam-
ples that you can download.

To help you find your way, if a code listing can be found in the download,
there’ll be a bar before the snippet (just like the one here).
Download rails40/demo1/app/controllers/say_controller.rb
class SayController < ApplicationController
➤ def hello
➤ end

def goodbye
end
end

This contains the path to the code within the download. If you’re reading
the ebook version of this book and your ebook viewer supports hyperlinks,
you can click the bar, and the code should appear in a browser window.
Some browsers may mistakenly try to interpret some of the HTML tem-
plates as HTML. If this happens, view the source of the page to see the
real source code.

And in some cases involving the modification of an existing file where the
lines to be changed may not be immediately obvious, you will also see
some helpful little triangles on the left of the lines that you will need to
change. Two such lines are indicated in the previous code.

David Says…
Every now and then you’ll come across a “David Says…” sidebar. Here’s
where David Heinemeier Hansson gives you the real scoop on some par-
ticular aspect of Rails—rationales, tricks, recommendations, and more.
Because he’s the fellow who invented Rails, these are the sections to read
if you want to become a Rails pro.

Joe Asks…
Joe, the mythical developer, sometimes pops up to ask questions about
stuff we talk about in the text. We answer these questions as we go along.

report erratum • discuss


Introduction • xvii

This book isn’t meant to be a reference manual for Rails. Our experience is
that reference manuals are not the way most people learn. Instead, we show
most of the modules and many of their methods, either by example or narra-
tively in the text, in the context of how these components are used and how
they fit together.

Nor do we have hundreds of pages of API listings. There’s a good reason for
this—you get that documentation whenever you install Rails, and it’s guaran-
teed to be more up-to-date than the material in this book. If you install Rails
using RubyGems (which we recommend), simply start the gem documentation
server (using the command gem server), and you can access all the Rails APIs
by pointing your browser at http://localhost:8808. You will find out in A Place for
Documentation, on page 265 how to build even more documentation and guides.

In addition, you will see that Rails helps you by producing responses that
clearly identify any error found, as well as traces that tell you not only the
point at which the error was found but also how you got there. You can see
an example in Figure 25, Our application spills its guts., on page 124. If you
need additional information, peek ahead to Section 10.2, Iteration E2: Handling
Errors, on page 124 to see how to insert logging statements.

Should you get really stuck, there are plenty of online resources to help. In
addition to the code listings mentioned, there is a forum,3 where you can ask
questions and share experiences; an errata page,4 where you can report bugs;
and a wiki,5 where you can discuss the exercises found throughout the book.

These resources are shared resources. Feel free to post not only questions
and problems to the forum and wiki but also any suggestions and answers
you may have to questions that others may have posted.

Let’s get started! The first steps are to install Ruby and Rails and to verify
the installation with a simple demonstration.

3. http://forums.pragprog.com/forums/148
4. http://www.pragprog.com/titles/rails4/errata
5. http://www.pragprog.com/wikis/wiki/RailsPlayTime

report erratum • discuss


Part I

Getting Started
In this chapter, we’ll see
• installing Ruby, RubyGems, SQLite3, and Rails; and
• development environments and tools.

CHAPTER 1

Installing Rails
In Part I of this book, we’ll introduce you to both the Ruby language and the
Rails framework. But we can’t get anywhere until you’ve installed both and
verified that they are operating correctly.

To get Rails running on your system, you’ll need the following:

• A Ruby interpreter. Rails is written in Ruby, and you’ll be writing your


applications in Ruby too. Rails 4.0 recommends Ruby version 2.0.0 but
will run on 1.9.3. It will not work on Ruby versions 1.8.7 or Ruby 1.9.2.

• Ruby on Rails. This book was written using Rails version 4.0 (specifically
Rails 4.0.0).

• A JavaScript interpreter. Both Microsoft Windows and Mac OS X have


JavaScript interpreters built in, and Rails will use the version already on
your system. On other operating systems, you may need to install a
JavaScript interpreter separately.

• Some libraries, depending on the operating system.

• A database. We’re using both SQLite 3 and MySQL 5.5 in this book.

For a development machine, that’s about all you’ll need (apart from an editor,
and we’ll talk about editors separately). However, if you are going to deploy
your application, you will also need to install a production web server (as a
minimum) along with some support code to let Rails run efficiently. We have
a whole chapter devoted to this, starting in Chapter 16, Task K: Deployment
and Production, on page 233, so we won’t talk about it more here.

So, how do you get all this installed? It depends on your operating system....

report erratum • discuss


Chapter 1. Installing Rails • 4

1.1 Installing on Windows


The easiest way to install Rails on Windows is by using the RailsInstaller1
package. At the time of this writing, the latest version of RailsInstaller is
version 2.2.1, which includes Ruby 1.9.3 and Rails 3.2. Until a new version
is released that supports Rails 4.0.0 or Ruby 2.0, feel free to use version 2.1
of RailsInstaller to get you started.

Base installation is a snap. After you download, click Run and then click
Next. Select “I accept all of the Licenses” (after reading them carefully of
course) and then click Next, Install, and Finish.

This opens a command window and prompts you for your name and email.
This is only to set up the git version control system. For the purposes of the
exercises in this book, you won’t need to worry about the ssh key that is
generated.

Close this window and open a new command prompt. On Windows 8, type
cmd on the tile-based Start screen and press Enter. On versions of Windows
prior to Windows 8, select Windows Start, select Run..., enter cmd, and click
OK.

Windows 8 users need to perform the additional step of installing node.js.2


Once this is complete, close the command window and open a new one for
the changes to %PATH% to take effect. Verify that the installation is correct by
entering the command node -v.

If you have trouble, try looking for suggestions on the Troubleshooting page
on the RubyInstaller site.3

As long as the version of RailsInstaller you used installed a version of Ruby


that is 1.9.3 or greater, there is no need to upgrade to a newer version of
Ruby. Please skip to Section 1.4, Choosing a Rails Version, on page 8 to
ensure that the version of Rails you have installed matches the version
described in this edition. See you there.

1.2 Installing on Mac OS X


Since Mac OS X ships with Ruby 1.8.7, you’ll need to download a newer ver-
sion of Ruby that works with Rails 4.0. The easiest way to do this is to use
RailsInstaller, which at the time of this writing installs Ruby 1.9.3. A second

1. http://railsinstaller.org/
2. http://nodejs.org/download/
3. https://github.com/oneclick/rubyinstaller/wiki/Troubleshooting

report erratum • discuss


Discovering Diverse Content Through
Random Scribd Documents
Funerals.—It was customary to place a plate of salt, the
smoothing iron, or a clod of green grass on the breast of a corpse,
while laid out previous to being coffined. This, it was believed, kept
it from swelling. A candle was left burning beside it all night. When it
was placed in the coffin and taken away on the day of the funeral,
the boards on which it had been lying were left for the night as they
were, with a drink of water on them, in case the dead should return
and be thirsty. Some put the drink of water or of milk outside the
door, and, as in Mull and Tiree, put a sprig of pearlswort above the
lintel to prevent the dead from entering the house.
When coffining the corpse every string in the shroud was cut with
the scissors; and in defence of the practice there was a story that,
after burial, a woman’s shade came to her friends, to say that all the
strings in her shroud had not been cut. Her grave was opened, and
this was found to be the case.
The only instance the writer has heard of Cere-cloth, that is, cloth
dipped in wax in which dead bodies were wrapped, being used in
the Highlands, is, that the Nicholsons of Scorrybreck, in Skye (a
family said to be of Russian descent through Neacal mòr who was in
Mungastadt), had a wax shirt (Leine Chéir) which, from the
friendship between themselves and the chief of the Macleods, was
sent for from Dunvegan on every occasion of a death.
The Watch of the Graveyard (Faire Chlaidh).—The person last
buried had to keep watch over the graveyard till the next funeral
came. This was called Faire Chlaidh, the graveyard watch, kept by
the spirits of the departed.
At Kiel (Cill Challum Chille), in Morvern, the body of the Spanish
Princess said to have been on board one of the Armada blown up in
Tobermory Bay was buried. Two young men of the district made a
paction, that whoever died first the other would watch the
churchyard for him. The survivor, when keeping the promised watch,
had the sight of his dead friend as well as his own. He saw both the
material world and spirits. Each night he saw ghosts leaving the
churchyard and returning before morning. He observed that one of
the ghosts was always behind the rest when returning. He spoke to
it, and ascertained it to be the ghost of the Spanish Princess. Her
body had been removed to Spain, but one of her little fingers had
been left behind, and she had to come back to where it was.
When two funeral parties met at the churchyard, a fight frequently
ensued to determine who should get their friend first buried.
Suicides.—The bodies of suicides were not taken out of the house,
for burial, by the doors, but through an opening made between the
wall and the thatch. They were buried, along with unbaptized
children, outside the common churchyard.
It was believed in the north, as in Skye and about Applecross (a
Chomrach) in Ross-shire, no herring would be caught in any part of
the sea which could be seen from the grave of a suicide.
Murder.—It was believed in Sutherlandshire that a murdered body
remained undecayed till touched.
The Harvest Old Wife (a Chailleach).—In harvest, there was a
struggle to escape being the last done with the shearing, and when
tillage in common existed, instances were known of a ridge being
left unshorn (no person would claim it) because of it being behind
the rest. The fear entertained was that of having the ‘famine of the
farm’ (gort a bhaile), in the shape of an imaginary old woman
(cailleach), to feed till next harvest. Much emulation and amusement
arose from the fear of this old woman; and from it arose the
expression, “Better is a mercy-leap in harvest than a sheaf
additional” (’As fearr leum-iochd a’s t’ fhogaradh na sguab a
bharrachd). The cum-iochd,67 or mercy-leap, is where a rocky
mound or a soft spot, where no corn grows, occurs in a ridge. Its
occurrence was a great help to the shearing being done.
The first done made a doll of some blades of corn, which was
called the ‘old wife,’ and sent it to his nearest neighbour. He in turn,
when ready, passed it to another still less expeditious, and the
person it last remained with had the ‘old woman’ to keep for that
year. The old wife was known in Skye as the Cripple Goat (a
Ghobhar Bhacach).
The fear of the Cailleach in harvest made a man in Saor-bheinn, in
the Ross of Mull, who farmed his land in common with another, rise
and shear his corn by moonlight. In the morning he found it was his
neighbour’s corn he had cut.
Big Porridge Day (La u Bhrochain mhòr).—In the Western Islands,
in olden times (for the practice does not now exist anywhere), when
there was a winter during which little sea-ware came ashore, and full
time for spring work had come without relief, a large dish of
porridge, made with butter and other good ingredients, was poured
into the sea on every headland where wrack used to come. Next day
the harbours were full.
This device was to be resorted to only late in the spring—the Iona
people say the Thursday before Easter—and in stormy weather. The
meaning of the ceremony seems to have been that, by sending the
fruit of the land into the sea, the fruit of the sea would come to
land.
Fires on Headlands.—In Skye, fires were lighted on headlands at
the beginning of winter to bring in herrings.
Stances.—Particular stances, or sites of buildings, were accounted
unlucky, such for instance as the site of a byre in which the death of
several cattle had occurred; and it was recommended, to prevent
the recurrence of such misfortunes, that the site should be altered.
Names.—So with regard to names. If the children of a family were
dying in infancy, one after the other, it was thought that, by
changing the name, the evil would be counteracted. The new name
was called a ‘Road name’ (Ainm Rathaid), being that of the first
person encountered on the road when going with the child to be
baptized. It was given ‘upon the luck’ (air sealbhaich) of the person
met.
The Mac-Rories, a sept of the Mac-Larens, in Perthshire, were
descendants of one who thus received his name. His parents, having
lost a previous child before its baptism, were advised to change the
name. They were on their way through the Pass, called Laìrig Isle,
between Loch Erne and Glen-dochart, to have their second child
baptized, when they were met by one Rory Mac Pherson. He was an
entire stranger to them, but turned back with them, as a stranger
ought to do to avoid being unlucky, and the child was called after
him. Clann ’ic-Shimigeir, a sept of the Mac Neills, have also a road
name.
Delivery of Cattle and Horses.—Before delivering a cow to the
buyer at a market, the seller should pass the end of the rope, by
which she is led, three times round his body. When taking delivery of
a horse, from one of whom you are not sure, you should come
deiseal between him and the horse, and take hold of the halter
inside his hand, that is, between him and the horse. Otherwise, the
seller’s eye will be after the beast.
Trades.—Masons were said to be able to raise the devil, or, as the
Gaelic expression more forcibly describes it, “to take the son of
cursing from his roots” (macmollachd thoirt as a fhriamhaichean).
Smiths, being people who work among iron, were deemed of more
virtue against the powers of evil than any other tradesmen.
Tailors were looked upon with a feeling akin to that entertained in
the south, where “nine tailors made a man.” The reason probably
was that in olden times every man fit to bear arms thought it
beneath him to follow a peaceful occupation, and only the lame and
cripple were brought up as tailors.
Tinkers are known as Luckd-Ceaird, that is literally ‘tradesmen,’
and the name is a memory of days when they held the first rank as
hand-craftsmen.
Saor, a joiner, means literally ‘a free-man,’ whence it would appear
that from the earliest times the trade was highly esteemed.
Iron.—An oath on cold iron was deemed the most binding oath of
any; when people swore on their dirks it was only because it was at
the time the cold iron readiest to hand. A man who secreted iron,
and died without telling where, could not rest in his grave. At Meigh,
in Lochaber, a ghost for a long time met people who were out late.
An old man, having taken with him a Bible and made a circle round
himself on the road with a dirk, encountered it, and, in reply to his
inquiries, the ghost confessed to having stolen a ploughshare (soc a
chroinn), and told where the secreted iron was to be found. After
this the ghost discontinued its visits to the earth.
Cold iron, e.g. the keys passed round the body of a cow, after her
return from the bull, keeps her from ath-dàir, that is, seeking to go
on the same journey again.
Empty Shells.—Empty whelk shells (Faochagun failmhe) should
not be allowed to remain in the house for the night. Something is
sure to come after them.
Similarly, water in which feet have been washed (i.e. out of which
the use or benefit has been taken) should not be left in the house
for fear the noiseless people come and plunge about in it all night.
Protection against Evil Spirits.—On every occasion of danger and
anxiety, the Highlander of former days commended himself to the
protection of the Cross. In a storm of thunder he blessed himself
saying, “the Cross of Christ be upon us.” When he encountered a
ghost or evil spirit at night, he drew a circle round himself on the
road with the point of his dirk, or a sapling in the name of Christ,
“the Cross of Christ be upon me,” and while he remained in the circle
no evil could come near him.
A person was also safe while below high-water mark. Fairies and
evil spirits had no power below the roll of sea-weed.
When walking the high road at night, it is recommended to keep
to the side paths in case of meeting the wraiths of funerals. The
ghostly train may throw a person down, or compel him to carry the
bier to the churchyard.
Misnaming a Person.—If a person be accidentally misnamed, as
e.g. being called John when his name is Donald, he who made the
mistake, on observing it, instantly exclaimed, “The Cross of Christ be
upon us.”
Gaining Straw (Sop Seile).—At certain seasons of the year,
principally at Beltane and Lammas, a wisp of straw, called Sop-seile
(literally a spittle wisp), was taken to sprinkle the door-posts and
houses all round sunwise (deiseal), to preserve them from harm.
When a new cow came home it was also sprinkled to preserve it
from the evil eye. The liquid used was menstruum.
In spring the horses, harness, plough, etc., were similarly
sprinkled before beginning to plough.
Propitious Times.—A great number of the observances of
superstition were regulated by days of the week or year. There were
certain days on which alone certain works could be commenced
under favourable auspices and with any chance of being successfully
done.
Unlucky Actions.—It is unlucky to wind black thread at night. A
vicious wish made to one another by women quarrelling, in olden
times, was, “The disease of women who wind black thread at night
be upon you!” Some say the reason of the evil omen is, that black
thread is apt to disappear at night, or be taken by the Fairies, and
be found through the house next morning. Superstition probably
assigned some more occult reason.
It is ‘little happiness’ for anyone to kill a magpie or a bat.
It is unlucky for a person on a journey to return the way he went.
This belief had its origin in the instructions given to the ‘man of God,’
who rebuked the idolatry of Jeroboam. “Eat no bread, nor drink
water, nor turn again by the same way that thou camest” (I Kings
xiii. 9).
CHAPTER VIII.

AUGURY.68

The anxiety of men to know the future, the issue of their labours,
and the destinies awaiting them, makes them ready listeners to the
suggestions of fancy, and an easy prey to deception. The mind
eagerly lays hold on anything that professes to throw light on the
subject of its anxiety, and men are willing victims to their own hopes
and fears. Where all is dark and inscrutable, deception and delusion
are easy, and hence augury of all kinds, omens, premonitions,
divinations, have ever exercised a noticeable power over the human
mind.
The ordinary manner which superstition takes to forecast the
future is to look upon chance natural appearances under certain
circumstances as indications of the character, favourable or
unfavourable, of the event about which the mind is anxious. Any
appearance in nature, animate or inanimate, can thus be made an
omen of, and an inference be drawn from it of impending good or
bad fortune. If it be gloomy, forbidding, awkward, or unpleasant, it is
an unlucky omen, and the subsequent event, with which the mind
associates it, will be unfavourable, but if pleasant, then it is a good
omen, and prognosticates pleasant occurrences.
Omens which proceed upon a similarity of character between the
prognostic and its fulfilment are easy of interpretation. There are
other omens which have no connection, natural, possible, or
conceivable, with the impending event, and of which consequently
the meaning is occult, known only to people of skill instructed in
their interpretation. These probably had their origin in one or two
accidental coincidences. For instance, if the appearance of a fox is to
be taken as an omen, it will naturally be taken as a bad sign, the
stinking brute can indicate nothing favourable; but no amount of
sagacity will teach a person that an itching in the point of his nose
prognosticates the receipt of important news, or the cuckoo calling
on the house-top the death of one of the inmates within the year.
His utmost acuteness will fail to find in a shoulder-blade any
indication of destiny, or any prophetic meaning in the sediment of a
cup of tea. The meaning of these is a mystery to the uninitiated, and
it is easy to see how they might be reduced to a system and lead to
the wildest delusions of fortune-telling.
Everything a Highlander of the old school set about, from the most
trifling to the most important, was under the influence of omens.
When he went to fish, to catch his horse in the hill, to sell or buy at
the market, to ask a loan from his neighbour, or whatever else he
left home to do, he looked about for a sign of the success of his
undertaking, and, if the omen were unpropitious, returned home. He
knew his journey would be of no avail. He consulted mystagogues as
to his fate, and at the proper seasons looked anxiously for the signs
of his luck. Like the rest of mankind, he was, by means of these,
pleased or depressed in anticipation of events that were never to
occur. Hence the saying, “Take a good omen as your omen, and you
will be happy.”
Probably the Greek μαντεία, prediction by an oracle, is cognate to
the Gaelic manadh, a foretoken, anything from which a prediction
can be drawn. Both among Greeks and Celts a great number of
omens were taken from birds.
As already mentioned, it is a bad sign of a person’s luck during the
day that he should rise from bed on his left hand, wash himself with
water in which eggs have been boiled, or the cakes for his breakfast
should frequently break in the baking, or fall backwards. The coming
evil can be averted in the latter case by giving plenty of ‘butter
without asking’ (Im gun iarraidh) with the cakes. Indeed, ‘butter
unasked for’ is of sovereign value as an omen of luck. A cake spread
with it, given to fishermen, secures a good day’s fishing. It is
reckoned good in diseases, particularly measles, and a most
excellent omen for people going on a journey. Its not being given to
Hugh of the Little Head, on the morning of his last battle, was
followed by his losing the battle and his life.
Omens are particularly to be looked for at the outset of a journey.
If the first animal seen by the traveller have its back towards him, or
he meet a sheep or a pig, or any unclean animal, or hear the shrill
cry of the curlew, or see a heron, or he himself fall backward, or his
walking-stick fall on the road, or he have to turn back for anything
he has forgot, he may as well stay at home that day; his journey will
not prosper. A serpent, a rat, or a mouse is unlucky unless killed, but
if killed becomes a good omen. If the face of the animal be towards
one, even in the case of unlucky animals, the omen becomes less
inauspicious.
It is of great importance what person is first met. Women are
unlucky, and some men are the most unfortunate omen that can be
encountered. These are called droch còmhalaichean, i.e. bad people
to meet, and it was told of a man in Skye, that to avoid the
mischance of encountering one of them when setting out on a
journey, he sent one of his own family to meet him. If he met any
other he returned home. In a village in Ayrshire there are three
persons noted for being inauspicious to meet, and fishermen (upon
whom as a class this superstition has a strong hold) are much
dissatisfied at meeting any of them. One of them is not so bad if he
puts his hand to his face in a manner peculiar to him. It is
inauspicious to meet a person from the same village as oneself, or a
man with his head bare, or a man going to pay rent. Old people
going to pay rent, therefore, took care to go away unobserved. A
plain-soled person is unlucky, but the evil omen in his case is averted
by rolling up the tongue against the roof of the mouth. The Stewarts
were said to have insteps; water flowed below their foot; it was,
therefore, fortunate to meet any of them. All risk of a stranger
proving a bad còmhalaiche is avoided by his returning a few steps
with the traveller.
A hare crossing one’s path is unlucky, and old people, when they
saw one before them, made considerable detours to avoid such a
calamity. The disfavour with which this harmless animal and the pig
were regarded no doubt arose from their being unclean under the
Levitical Law. The hare chews the cud, but divides not the hoof; the
pig divides the hoof, but does not chew the cud.
The fox is unlucky to meet, a superstition that prevails also in East
Africa. The King of Karague told Captain Speke that “if a fox barked
when he was leading an army to battle, he would retire at once,
knowing that this prognosticated evil” (Journal, p. 241).
It is unlucky to look back after setting out. Old people, if they had
to turn to a person coming after them, covered their face. This
superstition probably had its origin in the story of Lot’s wife. Fin
MacCoul, according to a popular tale, never looked back after setting
out on a journey. When he went on the expedition that terminated in
his being “in the house of the Yellow Forehead without liberty to sit
down or power to stand up,” he laid spells on his companions, that
no man born in Ireland should follow him. Fergus, who was born in
Scotland, followed, and Fin, hearing footsteps behind him, called out
without turning his head, in a phrase now obsolete, Co sid a
propadh mo cheaplaich? i.e., it is supposed, “Who is that following
my footsteps?”
To be called after is a sure omen that a person will not get what
he is going in search of. This belief gave great powers of annoyance
to people of a waggish humour. When everything prognosticated
success, and the fishing boat had left the shore, or the old man,
staff in hand, had set out on his journey, some onlooker cried out,
“There is the fox before you and after you”; or, “Have you got the
fish-hooks?” or, “Have you taken the Bait-stone?”69 Immediately a
damp was thrown on the expedition, a return home was made for
that day, and the wag might be glad if the party called after did not
make him rue his impertinence.
Of omens referring to other events in the life of man than the
success of particular expeditions may be mentioned the following:
A golden plover (Feadag, Charadrius pluvialis), heard at night,
portends the near approach of death or other evil. The cry of the
bird is a melancholy wailing note.
A pied wagtail (Breac an t-sìl, motaeilla alba), seen between them
and the house, was a sign of being turned out of the house that
year and ‘losing the site’ (call na làraich).
The mole burrowing below a house is a sign the tenants will not
stay long on that site.
If the cuckoo calls on the house-top, or on the chimney (luidheir),
death will occur in the house that year.
In spring and early summer the omens of happiness and
prosperity, or misery and adversity for the year, are particularly
looked for. It is most unfortunate if the first foal or lamb seen that
season have its tail toward the beholder, or the first snail (some say
stone-chat) be seen on the road or on a bare stone, and a most
unmistakable sign of misfortune to hear the cuckoo for the first time
before tasting food in the morning, ‘on the first appetite’ (air a chiad
lomaidh), as it is called. In the latter case, the cuckoo is said ‘to soil
upon a person’ (chac a chuthag air), and, to avoid such an indignity,
people have been known, at the time of the cuckoo’s visit, to put a
piece of bread below their pillow to be eaten the first thing in the
morning.
Cock-crowing before midnight is an indication of coming news. Old
people said the bird had ‘a tale’ to tell; and, when they heard it,
went to see if its legs were cold or not. If cold, the tale will be one
of death; if hot, a good tale. The direction in which the bird’s head is
turned indicates the direction in which the tale is to come.
In visiting the sick, it is a sign of the termination of the illness
whether it be the right or the left foot that touches the threshold
first.
Women pretended to know when they laid their hand on a sick
person whether he would recover.
It is a good sign if the face of the chimney-crook (aghaidh na
slabhraidh) be toward the visitor, but an evil omen if its back be
toward him.
CHAPTER IX.

PREMONITIONS AND DIVINATION.


PREMONITIONS.
These are bodily sensations by which future events may be
foreknown. An itching in the nose foretells that a letter is coming,
and this in olden times was a matter of no small consequence. There
is an itching of the mouth that indicates a kiss, and another
indicating a dram. A singing or tingling in the ears denotes death, a
friend at the moment of its occurrence has expired and news of his
death will be heard before long; an itching of the cheek or eyes,
weeping; itching of the left hand, money; of the right, that one is
soon to meet a stranger with whom he will shake hands; of the
elbow, that he will soon change beds or sleep with a stranger; of the
brow, that some person will make you angry before long.
Hot ears denote that some person is speaking about your
character. If the heat be in the right ear, he is supporting or praising
you; if in the left, he is speaking ill of you (Chluas dheas gam thoirt
a nuas; ’s a chluas chli gam shìor-chàineadh). In the latter case
persons of a vindictive nature repeated the following words:
“He who speaks of me,
If it be not to my advantage,
May he be tossed
On sharp grey knives,
May he sleep in an ant-hill,
And may it be no healthy sleep to him,
But a furious woman between him and the door,
And I between him and his property and sleep.”70

The evil wish went on, that “an iron harrow might scrape his
guts,” and something about “a dead old woman” that my informant
could not remember.
Trial (Deuchainn).—The deuchainn al. diachuinn, sometimes called
frìdh, omen, was a ‘cast’ or trial made by lots or other appeal to
chance to find out the issue of undertakings—whether an absent
friend was on his way home or would arrive safe; whether a sick
man will recover; whether good or bad fortune awaits one during
the year; what the future husband or wife is to be; the road stolen
goods have taken, etc. This cast may be either for oneself or for
another, “for him and for his luck” (air a shon ’s air a shealbhaich).
On New-Year day people are more disposed to wonder and speculate
as to their fortunes during the year upon which they have entered
than to reflect upon the occurrences of the past. Hence these ‘casts’
were most frequently made on that day. Another favourite time was
Hallowmas night. Most of them might be made at any time of the
year, and the difficulty was not in making them but in interpreting
them.
In making a ‘cast’ for one’s future partner, the approved plan is for
him to go at night to the top of a cairn or other eminence where no
four-footed beast can go, and whatever animal is thence seen or
met on the way home is an omen of the future husband or wife. It
requires great shrewdness to read the omen aright.
Another way is to shut the eyes, make one’s way to the end of the
house, and then, and not till then, open the eyes and look around.
Whatever is then seen is an indication of fortune during the year. It
is unlucky to see a woman, particularly an old woman bent with age
and hobbling past. A man is lucky, particularly a young man riding
gaily on a mettlesome horse. A man delving or turning up the earth
forebodes death; he is making your grave, and you may as well
prepare. A duck or a hen with its head below its wing is just as bad,
and the more that are seen in that attitude the speedier or more
certain the death. A man who had the second sight once made a
‘trial’ for a sick person at the request of an anxious friend. He went
out next morning to the end of the house in the approved manner.
He saw six ducks with their heads under their wings, and the sick
man was dead in less than two days.
Other seers, who made ‘trials’ for reward, made the person who
consulted them burn straw in front of a sieve and then look through
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookfinal.com

You might also like