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

Rails for PHP Developers 1st Edition Derek Devries instant download

The document provides information about the book 'Rails for PHP Developers' by Derek DeVries and Mike Naberezny, which serves as a guide for PHP developers transitioning to Ruby on Rails. It includes links to various resources and related books, along with reader testimonials praising its approachability and practical examples. The content outlines the structure of the book, covering topics from basic Ruby concepts to building Rails applications.

Uploaded by

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

Rails for PHP Developers 1st Edition Derek Devries instant download

The document provides information about the book 'Rails for PHP Developers' by Derek DeVries and Mike Naberezny, which serves as a guide for PHP developers transitioning to Ruby on Rails. It includes links to various resources and related books, along with reader testimonials praising its approachability and practical examples. The content outlines the structure of the book, covering topics from basic Ruby concepts to building Rails applications.

Uploaded by

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

Rails for PHP Developers 1st Edition Derek

Devries pdf download

https://ebookname.com/product/rails-for-php-developers-1st-
edition-derek-devries/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Ruby for Rails Ruby techniques for Rails developers


David Black

https://ebookname.com/product/ruby-for-rails-ruby-techniques-for-
rails-developers-david-black/

Foundation Flex for Developers Data Driven Applications


with PHP ASP NET ColdFusion and LCDS 1st Edition Sas
Jacobs

https://ebookname.com/product/foundation-flex-for-developers-
data-driven-applications-with-php-asp-net-coldfusion-and-
lcds-1st-edition-sas-jacobs/

Docker for Rails Developers Build Ship and Run Your


Applications Everywhere 1 edition (February 24, 2019)
Edition Rob Isenberg

https://ebookname.com/product/docker-for-rails-developers-build-
ship-and-run-your-applications-everywhere-1-edition-
february-24-2019-edition-rob-isenberg/

Fight or Pay Soldiers Families in the Great War 1st


Edition Desmond Morton

https://ebookname.com/product/fight-or-pay-soldiers-families-in-
the-great-war-1st-edition-desmond-morton/
Pro C 2008 and the NET 3 5 Platform 4th Edition Andrew
Troelsen

https://ebookname.com/product/pro-c-2008-and-the-
net-3-5-platform-4th-edition-andrew-troelsen/

Twenty Years of Education Transformation in Gauteng


1994 To 2014 1st Edition Felix Maringe

https://ebookname.com/product/twenty-years-of-education-
transformation-in-gauteng-1994-to-2014-1st-edition-felix-maringe/

Literacy with an Attitude Second Edition Educating


Working Class Children in Their Own Self Interest
Patrick J. Finn

https://ebookname.com/product/literacy-with-an-attitude-second-
edition-educating-working-class-children-in-their-own-self-
interest-patrick-j-finn/

The Checklist What You and Your Family Need to Know to


Prevent Disease and Live a Long and Healthy Life Fifth
Edition Manny Alvarez

https://ebookname.com/product/the-checklist-what-you-and-your-
family-need-to-know-to-prevent-disease-and-live-a-long-and-
healthy-life-fifth-edition-manny-alvarez/

Introduction to Functional Equations 1st Edition


Prasanna K. Sahoo

https://ebookname.com/product/introduction-to-functional-
equations-1st-edition-prasanna-k-sahoo/
Deep Learning with Keras Implementing Deep Learning
Models and Neural Networks with the power of Python 1st
Edition Antonio Gulli

https://ebookname.com/product/deep-learning-with-keras-
implementing-deep-learning-models-and-neural-networks-with-the-
power-of-python-1st-edition-antonio-gulli/
What readers are saying about Rails for PHP Developers

This is a thorough and approachable introduction to Ruby and Rails


for PHP programmers from fellow developers who are well-versed in
both Ruby and PHP.
Paul M. Jones
Lead Developer on the Solar Framework for PHP

As a PHP developer, I found the book focused well on the transition


from coding PHP to coding Ruby (and Rails) and that it gave great
examples of translating common PHP idioms to Ruby.
Matthew Weier O’Phinney
PHP Developer and Zend Framework Core Contributor

The quality of the writing is superb, the challenges and examples are
engaging, and the PHP to Ruby information is a valuable resource.
The exercises are nice, are short, and follow the topic well, giving
readers some creative time between each chapter.
Mislav Marohnić
Prototype JavaScript Framework Core Developer

This is an enjoyable book packed with great information and usable


examples. I like the organization of the book and the gentle, infor-
mal voice with which the authors cover many complex topics. It’s easy
to read, yet it has plenty of substance and depth to give the reader a
great introduction to Rails.
Bill Karwin
MySQL Guild and Former Zend Framework Project Leader
Rails for PHP Developers
Derek DeVries
Mike Naberezny

The Pragmatic Bookshelf


Raleigh, North Carolina Dallas, Texas
Many of the designations used by manufacturers and sellers to distinguish their prod-
ucts 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 and the linking g
device are trademarks 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://www.pragprog.com

Copyright © 2008 Derek DeVries and Mike Naberezny.

All rights reserved.

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


ted, 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-10: 1-934356-04-2
ISBN-13: 978-1-9343560-4-3
Printed on acid-free paper with 50% recycled, 15% post-consumer content.
First printing, January 2008
Contents
Acknowledgments 10

Preface 11
What Rails Offers . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Who Should Read This Book . . . . . . . . . . . . . . . . . . . 12
Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
PHP and Rails: A Personal View . . . . . . . . . . . . . . . . . . 13
About the Code Examples . . . . . . . . . . . . . . . . . . . . . 14
About the Environment Used . . . . . . . . . . . . . . . . . . . 14
Version Requirements . . . . . . . . . . . . . . . . . . . . . . . 15
How to Read This Book . . . . . . . . . . . . . . . . . . . . . . . 15

I From PHP to Rails 17

1 Getting Started with Rails 18


1.1 Rails as an Extension of Ruby . . . . . . . . . . . . . . 18
1.2 The Components of Rails . . . . . . . . . . . . . . . . . 19
1.3 Opinionated Software . . . . . . . . . . . . . . . . . . . 20
1.4 The MVC Pattern and Rails . . . . . . . . . . . . . . . . 22
1.5 Installing Ruby and Rails . . . . . . . . . . . . . . . . . 24
1.6 Creating a Rails App . . . . . . . . . . . . . . . . . . . . 25
1.7 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . 42
1.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

2 Beginning Ruby Code 43


2.1 Seeing Ruby as a General-Purpose Language . . . . . 43
2.2 Interacting with Ruby . . . . . . . . . . . . . . . . . . . 45
2.3 Objectifying Everything . . . . . . . . . . . . . . . . . . 47
2.4 Accepting Ruby’s Object World . . . . . . . . . . . . . . 48
2.5 Assigning to Variables . . . . . . . . . . . . . . . . . . . 50
2.6 Writing Methods and Passing Parameters . . . . . . . . 53
2.7 Controlling Program Flow . . . . . . . . . . . . . . . . . 57
CONTENTS 6

2.8 Handling Errors . . . . . . . . . . . . . . . . . . . . . . . 59


2.9 Understanding Blocks . . . . . . . . . . . . . . . . . . . 65
2.10 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . 70
2.11 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

3 Embracing the Ruby Philosophy 72


3.1 Thinking in Objects . . . . . . . . . . . . . . . . . . . . 72
3.2 Understanding Attributes . . . . . . . . . . . . . . . . . 75
3.3 Method Visibility . . . . . . . . . . . . . . . . . . . . . . 77
3.4 Understanding Typing . . . . . . . . . . . . . . . . . . . 79
3.5 Implementing Interfaces with Mixins . . . . . . . . . . 84
3.6 Organizing Code with Namespaces . . . . . . . . . . . . 88
3.7 Overriding Operators . . . . . . . . . . . . . . . . . . . . 91
3.8 Reopening Classes . . . . . . . . . . . . . . . . . . . . . 93
3.9 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . 95
3.10 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

II Building a Rails Application 96

4 Modeling the Domain 97


4.1 Defining Requirements . . . . . . . . . . . . . . . . . . 98
4.2 Using the Database . . . . . . . . . . . . . . . . . . . . 101
4.3 Creating the Application . . . . . . . . . . . . . . . . . . 104
4.4 Generating the First Model . . . . . . . . . . . . . . . . 106
4.5 Building Database Tables . . . . . . . . . . . . . . . . . 108
4.6 Employing ActiveRecord . . . . . . . . . . . . . . . . . . 113
4.7 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . 118
4.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

5 Working with Controllers and Views 120


5.1 Identifying Resources . . . . . . . . . . . . . . . . . . . 120
5.2 Creating Controllers . . . . . . . . . . . . . . . . . . . . 122
5.3 Routing Requests . . . . . . . . . . . . . . . . . . . . . . 125
5.4 Retrieving Meeting Data . . . . . . . . . . . . . . . . . . 129
5.5 Viewing Meetings . . . . . . . . . . . . . . . . . . . . . . 131
5.6 Adding Links . . . . . . . . . . . . . . . . . . . . . . . . 132
5.7 Creating New Meetings . . . . . . . . . . . . . . . . . . 138
5.8 Redirection and Flash Data . . . . . . . . . . . . . . . . 143
5.9 Administrating Meetings . . . . . . . . . . . . . . . . . . 145
5.10 Separating Public Files . . . . . . . . . . . . . . . . . . 153
5.11 Adding a Layout . . . . . . . . . . . . . . . . . . . . . . 155
CONTENTS 7

5.12 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . 158


5.13 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 160

6 Validating and Testing Models 161


6.1 Validating Model Data . . . . . . . . . . . . . . . . . . . 161
6.2 Using Rails Environments . . . . . . . . . . . . . . . . . 164
6.3 Testing Our Models . . . . . . . . . . . . . . . . . . . . . 165
6.4 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . 171
6.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

7 Authenticating Users 173


7.1 Migrating to a More Secure User . . . . . . . . . . . . . 173
7.2 User Registration . . . . . . . . . . . . . . . . . . . . . . 175
7.3 Viewing and Editing Users . . . . . . . . . . . . . . . . 186
7.4 Restoring Sessions . . . . . . . . . . . . . . . . . . . . . 192
7.5 Logging In . . . . . . . . . . . . . . . . . . . . . . . . . . 195
7.6 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . 200
7.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

8 Defining Associations 202


8.1 Connecting Presentations . . . . . . . . . . . . . . . . . 202
8.2 Testing Associations . . . . . . . . . . . . . . . . . . . . 205
8.3 Integrating Presentations into Meetings . . . . . . . . . 207
8.4 Routing Presentations . . . . . . . . . . . . . . . . . . . 208
8.5 The Presentation Controller . . . . . . . . . . . . . . . . 210
8.6 Spring Cleaning . . . . . . . . . . . . . . . . . . . . . . . 215
8.7 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . 221
8.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 222

9 Preparing to Launch 223


9.1 Adding the Home Page . . . . . . . . . . . . . . . . . . . 223
9.2 Securing Our Actions . . . . . . . . . . . . . . . . . . . 226
9.3 Protecting from Mass Assignment . . . . . . . . . . . . 232
9.4 Caching the Pages . . . . . . . . . . . . . . . . . . . . . 234
9.5 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . 240
9.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 240

10 Deploying the Application 242


10.1 Choosing a Host . . . . . . . . . . . . . . . . . . . . . . 243
10.2 The Production Environment . . . . . . . . . . . . . . . 245
10.3 Preparing Our Application . . . . . . . . . . . . . . . . . 246
10.4 Preparing Our Deployment Server . . . . . . . . . . . . 248
CONTENTS 8

10.5 Launching the Application . . . . . . . . . . . . . . . . 253


10.6 Enhancing Performance . . . . . . . . . . . . . . . . . . 256
10.7 Scaling Your Application . . . . . . . . . . . . . . . . . . 260
10.8 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . 261
10.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 262

III PHP to Ruby at a Glance 263

11 PHP to Ruby Basics Reference 264


11.1 Basic Syntax . . . . . . . . . . . . . . . . . . . . . . . . 264
11.2 Basic Data Types . . . . . . . . . . . . . . . . . . . . . . 266
11.3 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
11.4 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . 292
11.5 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . 294
11.6 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . 296
11.7 Control Structures . . . . . . . . . . . . . . . . . . . . . 305

12 PHP to Ruby Advanced Reference 316


12.1 Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
12.2 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 318
12.3 Classes and Objects . . . . . . . . . . . . . . . . . . . . 326
12.4 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . 354
12.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . 355
12.6 External Libraries and Packages . . . . . . . . . . . . . 357
12.7 Documenting Code . . . . . . . . . . . . . . . . . . . . . 359

13 PHP to Rails Reference 371


13.1 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . 371
13.2 $_GET/$_POST . . . . . . . . . . . . . . . . . . . . . . . 372
13.3 $_FILES . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
13.4 $_SERVER . . . . . . . . . . . . . . . . . . . . . . . . . . 376
13.5 Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
13.6 Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
13.7 Headers and Redirection . . . . . . . . . . . . . . . . . 380
13.8 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
13.9 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . 386
13.10 Accessing the Database . . . . . . . . . . . . . . . . . . 388
13.11 Email . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
13.12 Testing Rails Code . . . . . . . . . . . . . . . . . . . . . 391
13.13 Rails Plug-Ins . . . . . . . . . . . . . . . . . . . . . . . . 396
CONTENTS 9

Bibliography 399

Index 400
Acknowledgments
Derek would like to thank Melissa, daVinci, and his new baby girl,
Sevilla, who was born during the writing of this preface.
Mike would like to thank Kathy for her support and his parents for
buying his first computer, the Commodore 64.
We’d like to thank our reviewers: Bill Karwin, Mislav Marohnic, Tim
Fletcher, Paul M. Jones, Matthew Weier O’Phinney, Dallas DeVries,
Laura Thomson, and Chuck Hagenbuch. Their expertise, time, and
effort have been invaluable to us.
We’d like to thank the Pragmatic Programmers for giving us a great
opportunity to spread the word of Rails and our editor, Susannah, for
keeping us on track.
Thanks to everyone building open source software that we use and love,
from Rails to PHP. They truly make our working lives so much easier to
enjoy.
Preface
There is no doubt that by now you’ve heard all of the hype about Ruby
on Rails. It has been generating a lot of buzz with the promise of making
web applications fast and simple to create, and you may be wondering
what the big deal is. We know that PHP has been doing this for years
and has proven quite capable by its use in large companies such as
Yahoo. You may be wondering whether it’s worth the time investment
to learn Rails and Ruby, when you already have PHP under your belt.

What Rails Offers


Rails embraces a general development philosophy that sets a high pri-
ority on creating maintainable code. By following some simple guide-
lines, you should be able to keep a uniform pace of development and be
free to change your code with little fear of breaking existing functional-
ity. Rails achieves this by cherry-picking proven web development pat-
terns and best practices. These are two of the most important principles
Rails follows:
• Convention over configuration
• Don’t repeat yourself (DRY)
Rails defines the directory structure of your application for you and sets
a series of conventions for naming files, classes, and database tables.
It takes advantage of these conventions to tie together your applica-
tion without a lot of configuration. You may initially be resistant to the
idea of Rails telling you how to structure your application, but your
first Rails application will quickly demonstrate the efficiency that these
conventions offer you. By choosing smart defaults, Rails allows you to
focus on the functionality of your application instead of on the skeleton.
W HO S HOULD R EAD T HIS B OOK 12

Rails developers tend to be almost religious about the DRY principle.


Functionality is written cleanly once, and only once. Rails provides an
environment that makes it easy to consolidate shared code between
different components of your application.
Rails gives first-class importance to testing. Writing code is always done
in parallel with tests to ensure the code works as intended and will
continue to work when things around it change. In PHP, the uptake of
testing culture has been slow, and the methodologies for testing entire
applications are not clear. Ruby’s dynamic and flexible object model,
along with its standard library, makes unit testing easy. The Rails stack
builds on this to provide clear, built-in support for testing all parts of a
web application from the first line of code.

Who Should Read This Book


This book is meant for PHP developers who are interested in adding
Rails to their toolsets. There are a lot of books on Rails now, but PHP
developers have a unique way of thinking about problems that are built
around the PHP mind-set. This book aims to guide your learning in
Rails based on your existing knowledge of programming in PHP. An
understanding of object-oriented programming in PHP will help but is
not entirely necessary. This should be something you start to pick up
naturally while programming in Ruby.
Through this book, you will likely learn valuable lessons from Rails
that will inform future PHP development. Rails assembles a collection
of patterns and practices that are not new in themselves. Many of the
patterns in Rails can be implemented in other languages and may help
inspire some new approaches in your PHP code. However, the greatest
feature of Rails by far is Ruby! Throughout the book, we will explore
the power and productivity of Rails together. As you read, also be open
to Ruby itself, and be sure to absorb how Ruby forms the foundation of
Rails.

Resources
All code samples are available as an archive online.1 This book is inter-
active, so make sure to download and view the sample code as you
work. Reading Ruby code is one of the best ways to learn the language.

1. http://www.pragprog.com/titles/ndphpr/source_code
PHP AND R AILS : A P ERSONAL V IEW 13

We have built a companion website for this book that is also available
online.2 We will keep this website up-to-date with further code exam-
ples, resources, and answers to frequently asked questions. Be sure to
subscribe to the feed to keep up-to-date with future articles.

PHP and Rails: A Personal View


Since the introduction of PHP 5, we’ve witnessed an evolution in PHP’s
capabilities. Perhaps even more than changes in PHP itself, we’ve seen
a transformation in the way programmers use it. Object-oriented pro-
gramming has become more commonplace. As a result, professional
software engineering practices such as unit testing have become more
practical and accessible to PHP developers.
We were early adopters of PHP 5. When Rails came along, we were al-
ready sold on writing object-oriented, well-separated applications with
tests in PHP. Initially, we were a bit skeptical and didn’t have much
incentive to try Rails. We’re glad we did. We’re now excited about Rails
and enjoy building applications with it. We think you will as well, but
you’ll need to read the book and draw your own conclusions. We’ve
designed this book to be the guide that we wished we had when we
were in your shoes.
There are some software methodologies that we believe are applicable
to nearly all projects, such as the importance of object orientation and
unit testing. These opinions show in our writing. However, many other
factors determine how an application should be built and what tools
should be used. We believe that PHP, Ruby, and Rails are all just tools
you can choose from to build great applications.
It also might interest you to know that in our consulting practice, Main-
tainable Software,3 we still develop roughly half of our new applications
in PHP 5 (with the other half being mostly Rails). This should tell you
that we think PHP is a formidable platform, and it’s not about “switch-
ing” from one to the other. Learning Rails is just about having a new
tool to apply to your problems when it’s a good fit.

2. http://railsforphp.com
3. http://maintainable.com
A BOUT THE C ODE E XAMPLES 14

About the Code Examples


There are many different ways of building PHP applications. Many PHP
projects are developed from scratch, and an increasing number are
developed using one of the many frameworks available. In our exam-
ples, we chose a framework-agnostic approach to programming PHP so
that you can understand examples without previous knowledge of any
specific PHP framework.
To save space in the book, we usually leave off the leading <?php tag
when the example contains only PHP code. This means that if you want
to run these examples on your own, you’ll need to add this, or else PHP
will simply echo the code back to you.
We capitalize references to Ruby—the programming language—and
Rails—the framework. When you see ruby or rails in all lowercase, we
are instead referencing commands used to invoke the Ruby command-
line interpreter or the Rails framework generator, respectively.
PHP and Ruby code snippets use an icon in the sidebar to easily differ-
entiate between examples written in the two languages.
PHP Download preface/hello.php

function sayHello() {
print "Hello World!";
}

Ruby Download preface/hello.rb

def say_hello
print "Hello World!"
end

About the Environment Used


Examples and screenshots in this book were created with Mac OS X and
Safari, but the examples should run in all modern development envi-
ronments. Rails operates under the assumption that you have some
basic knowledge of command-line operations. It is well worth learning
the command-line basics of your preferred environment if you haven’t
already done so.
Command-line examples are shown running in a bash shell, so you
may find that you need to make some small adjustments based on
your environment.
V ERSION R EQUIREMENTS 15

Command-line prompts in this book display the base name of the cur-
rent working directory. The following example shows a command run
from the newsletter directory:
newsletter> ruby script/console

Version Requirements
Throughout the book, we compare code examples between PHP and
Ruby. The PHP examples will work on PHP 5.1 or newer. For those of
you who are still working primarily with PHP 4, you may occasionally
see PHP features mentioned that you haven’t used yet, such as excep-
tions. You’ll want to consult the PHP manual on these as you go.
The Ruby and Rails examples will all run on recent Ruby versions but
are especially geared toward Ruby 1.8.5 and newer. Before we give any
examples in Ruby, we talk about the installation and give you some
pointers on where to get the software you’ll need.
The Rails code is intended to work on Rails 2.0 or newer. We take full
advantage of new features and conventions in this version of Rails, so
most of the code will not work correctly on previous versions.

How to Read This Book


The goal of this book is to get you up to speed with both the Ruby
language and the Rails framework. To do this, we’ve divided the book
into three parts:
• Part I, “From PHP to Rails”
• Part II, “Building a Rails Application”
• Part III, “PHP to Ruby at a Glance”
The first part—“From PHP to Rails”—introduces the Model/View/Con-
troller pattern with the conversion of a simple PHP application to Rails.
This part then presents an introduction of Ruby to lay the foundation
for building a larger Rails application.
The second part—“Building a Rails Application”—guides you through
an in-depth application tutorial, from project conception all the way to
deployment. This part will cover the meat of building web applications
“the Rails way.”
H OW TO R EAD T HIS B OOK 16

The third and final part—“PHP to Ruby at a Glance”—provides an in-


depth reference that maps PHP syntax and idioms to comparable Ruby
and Rails code. We provide one-to-one corresponding Ruby and PHP
code wherever possible to make the translation easy.
Both Ruby and Rails are invaluable development tools with their own
respective strengths and weaknesses. By the end of this book, you’ll
have a good understanding of both these tools and will be able to add
not only one but two new tricks to your development toolbox. Although
we’ll use PHP to drive our learning of Rails, Rails can help us learn
about PHP as well. As developers, we’re always on a quest to find faster
and more efficient ways to do our job. We hope that Rails inspires you
to do just that.
Part I

From PHP to Rails


Chapter 1

Getting Started with Rails


In this chapter we’ll begin our Rails journey by focusing on the basic
concepts that drive the Rails framework. We’ll then get up and running
quickly by installing Rails and building a small test application.
The Rails framework is built using the Ruby programming language,
and a better understanding of Ruby is essential to mastering Rails.
Don’t worry if you’re not familiar with Ruby, though. Many developers
end up learning Ruby as they are learning Rails. The next few chapters
will get you up to speed with the Ruby language and how the Ruby
programming philosophy differs from PHP.

1.1 Rails as an Extension of Ruby


David Heinemeier Hansson extracted Rails from an application he wrote
for his company, 37signals. He released it as open source in 2004, and
there is now a group of developers on the core team actively apply-
ing features and patches to Rails. David’s original framework actually
began in PHP, but he later found Ruby to be a much better fit for what
he needed to do.
You’ll find the expressiveness of Ruby embraced fully in Rails to create
language conventions that are specific to Rails. The Rails core team is
concerned about creating a syntax that is friendly to humans. In lan-
guages such as C and PHP, we sometimes get lost in curly brackets and
semicolons that make us feel like programs are written for machines.
In good Ruby programs like Rails, programs always feel like they are
written for humans.
T HE C OMPONENTS OF R AILS 19

Rails takes advantage of numerous powerful Ruby features that allow


classes and methods to be created and modified at runtime. By using
the dynamic nature of Ruby, we can write incredibly flexible programs.
This dynamic nature can also help keep our application code as clean
and DRY as possible.
The Rails framework is composed of several different Ruby libraries.
As an introduction to Rails, let’s start by taking a look at the different
components that make up the framework.

1.2 The Components of Rails


Rails is a full stack framework, which means it contains all the tools
needed to get a basic application up and running. The Rails stack is
split into various components that we’ll often refer to by name. These
are some of the components that we’ll talk about most.
ActiveRecord
This is the heart of most Rails applications and is an object rela-
tional mapper (ORM) that maps database tables to objects in our
application. We’ll use this exclusively when interacting with the
database.
ActionPack
This part of Rails handles the request/response cycle and includes
the template and rendering part of our application.
ActiveSupport
This part of Rails provides shared code that is used to build many
of the other Rails components. It also contains additional func-
tionality ranging from multibyte character support to date and
time logic.
ActionMailer
This part will help us build and send email messages from within
our application.
Rake
This is a tool used to execute different tasks in our application.
These tasks include running tests, building documentation, and
doing much more. This is not a component of the Rails package
per se but is a Ruby tool that is tightly integrated into the Rails
workflow.
O PINIONATED S OFTWARE 20

Some components such as ActiveRecord and Rake are not exclusive to


Rails and are pretty useful as independent libraries outside the frame-
work. We’ll go over each of these components in more depth later as we
interactively learn Rails. Although we’ll learn most of Rails by writing
code, making the transition from PHP to Ruby and Rails is more than
learning a new language syntax. Before we start coding, let’s go over
some of the Rails conventions that will inform the decisions we make
as we write our applications.

1.3 Opinionated Software


The Ruby and Rails culture is quite different from that in PHP, and
this is reflected in both the code and the community. Rails is consid-
ered opinionated code, and it’s important to understand where and why
Rails expects you to follow certain coding principles and conventions.
Rails code has been heavily influenced by the coding style prevalent
in Ruby, and the Rails community places a high importance on code
beauty and readability. Although Ruby often allows more than one way
to do something, only one approach is usually considered correct by
community standards. Rubyists always give priority to clear and con-
sistent code over complex or cryptic code.
Rails is built with a distinct vision of how web applications should be
written. The Rails team regularly takes the role of a benevolent dictator
by imposing opinions they think are in your best interest when writing
software. Don’t get too worried if you initially are taken back by some
of these choices. Sometimes it takes a while to get used to a different
way of working. We suggest you follow the conventional workflow for at
least your first couple Rails applications. As the adage goes, “It’s good
to learn the rules before you decide to break them.”

Embracing the 80/20 Rule


The Rails framework aims to remain simple by following the 80/20 rule.
Rails aspires to solve 80 percent of the most common issues encoun-
tered when building a web application. This means that Rails limits or
rejects features and patches that will not benefit the majority of devel-
opers using it. There is an important drive in the Rails community to
keep the framework as lightweight as possible and to avoid unnecessary
feature bloat.
O PINIONATED S OFTWARE 21

This does not mean that Rails cannot handle your application’s needs.
It just means that the solution might not be in the core Rails frame-
work and is not much different from PHP in this respect. Rails makes
it quite easy to override behavior or add custom functionality to your
application using a Rails plug-in. If you’re running into a issue with
the framework, there is a good chance that someone may have already
written a Rails plug-in or Ruby library that solves your problem.

Following Conventions
Rails takes coding standards further by imposing rules and conventions
that are fairly easy to follow. Some of these decisions such as class and
database naming conventions are typically left to the developer when
creating a new application in PHP. You’ll quickly notice that not hav-
ing to make these judgments yourself actually speeds up development
time and creates a more consistent code base between different teams
members and projects.
Your first instinct may be to do things the way you’ve always been doing
them in PHP. Although old habits die hard, you’ll be rewarded for fol-
lowing the path of least resistance in Rails.

Increasing Productivity Through Beauty


It may seem like a strange statement, but one of the core ideas behind
Rails is that of maintaining a beautiful code API. One of the prime moti-
vating factors behind productive employees is that they enjoy the code
they are working with. You’ll notice that the Rails framework goes to
great lengths to provide an API that is predictable and beautiful to work
with.
A good example of this concept is in validation declarations. Ruby’s
flexible syntax enables us to call methods without parentheses. This
results in creating a naturally readable validation syntax that is obvious
to even those with no Ruby programming experience.
class Movie < ActiveRecord::Base
validates_presence_of :title, :on => :create
end

This example validates that a title is present when a movie is created.


The code is quite expressive and is easy to read and maintain.
T HE MVC P ATTERN AND R AILS 22

1.4 The MVC Pattern and Rails


One of the most important opinions that Rails asserts is how to orga-
nize your application code. Rails uses the classic design concept of
Model/View/Controller (MVC) to do this. MVC is a pattern used to man-
age applications that apply some type of user interface. The concept
actually dates back to the 1970s but in recent years has become quite
popular in creating web applications. It is used in varying forms within
most modern web frameworks. A fairly large number of MVC-based
frameworks exist for PHP as well, and prior knowledge of any of these
will also help you grasp how MVC works in Rails.
MVC splits your code into three distinct roles of responsibility and aims
to clearly separate your domain logic from your user interface logic.
If you use a PHP template engine such as Smarty, Flexy, or Savant,
you already understand how important this is in creating maintain-
able code. The MVC pattern goes a little further than most PHP tem-
plate solutions by adding a layer between the database and templates.
The controller layer is the plumbing that connects the business and
database logic to the template logic.

Model
The model is the foundation of your application and consists of the
nonvisual aspects of “things” in your application. The model contains
all your interaction with the database as well as any behavior that
enhances or changes data in the database. This includes simple for-
matting and validation of the data as well as some data integrity.
Being nonvisual usually makes testing this type of data simple and
reliable. The main goals of the model layer is to represent your data in
a way that can be used among various interfaces without duplicating
code. When you think “model,” you should think business logic.

View
The view is the visual representation of your application, as well as sim-
ple logic specific to rendering the user interface. In web applications,
this is usually (X)HTML markup or JavaScript code. In today’s Web 2.0
world, you may also need to render XML in response to web service
requests. When you think “view,” think of your application’s front-end
logic and templates.
T HE MVC P ATTERN AND R AILS 23

Figure 1.1: Model/View/Controller

Controller
The controller directs the traffic by handling requests sent to your
application and determining the right code to execute. It plays an im-
portant role in keeping your data loosely coupled by acting as an inter-
mediate layer between the model and the view.
The controller also maintains the state of your application using cook-
ies and session data. When you think “controller,” think of the event
handler that ties together the model and view layers.
The diagram in Figure 1.1 illustrates the three components of MVC and
shows a typical request/response cycle associated with Rails.
1. The browser sends a request to your application in the form of a
URL and GET/POST parameters.
2. The controller figures out what part of your code should deal with
this particular request. It then asks the model layer for any data
needed to perform that action.
3. The model queries the database to change or retrieve data and
hands the results back to the controller.
4. The controller passes the data to the view for use in the page
template.
I NSTALLING R UBY AND R AILS 24

5. The controller renders the view in a response sent back to the


browser.
Now that we have an idea of how the MVC pattern is used to organize
code in our application, we’ll put it to use by building a Rails applica-
tion using these principles. Before we build an application, however, we
need to get Rails installed.

1.5 Installing Ruby and Rails


Installation is different on various platforms, and there are some great
packages that simplify the Rails install process. You can find the most
up-to-date install process on the Rails download page.1
Although often thought of as a single unit, Ruby and Rails are two
separate packages. Rails is a framework written in the Ruby language,
not unlike frameworks such as Cake and the Zend Framework in PHP.
To get Rails working, your first step will be to get Ruby installed on
your machine. We recommend installing Ruby version 1.8.6 or newer.
You can find detailed information on installing Ruby across a variety of
platforms in the download area of the Ruby website.2
Once you have Ruby installed, we have to take a quick look at pack-
age management in Ruby. The most common method of distribution
for Ruby packages and libraries is through RubyGems. RubyGems is
a package manager similar to PEAR for PHP, and Rails is most easily
installed on your computer through a gem. We recommend installing
RubyGems 1.0.1 or newer, which you can download from the Ruby-
Forge website.3
Once you’ve downloaded the latest version of RubyGems, unpack the
contents, and run the following (as root when appropriate).
src> cd rubygems-*
rubygems-1.0.1> ruby setup.rb

install -c -m 0644 ...


...done.
No library stubs found.

1. http://rubyonrails.org/down
2. http://www.ruby-lang.org/en/downloads/
3. http://rubyforge.org/frs/?group_id=126
C REATING A R AILS A PP 25

This will install all the necessary files to get us going with RubyGems,
along with the gem command. The gem command is what we’ll use to
install Rails.
This book was written using Rails 2.0.2, and you’ll need at least this
version to run the code example in this book. If you already have a
previous version of Rails installed, you need to first remove any existing
Rails gem to make sure you’re using the version that the book is written
to work with. All gem install/uninstall commands need to be run as the
root user on *nix-based systems.
work> gem uninstall rails
Successfully uninstalled rails version 1.2.3
Remove executables and scripts for
'rails' in addition to the gem? [Yn] Y
Removing rails

Let’s now install Rails.


work> gem install rails
Successfully installed rails-2.0.2

Congratulations, you should now have Ruby and Rails up and run-
ning on your system. To make sure that we’re working with the correct
version of Rails, we can run the rails command with the -v option.
work> rails -v
Rails 2.0.2

Although Rails works with a variety of databases, the examples in this


book assume you are using MySQL. You may even have MySQL on
your system already since it is often the database of choice for PHP
developers.
Rails is an opinionated web framework, and one of the opinions is that
you will use Subversion.4 Doing so will reward you with nice features
of Rails that integrate well with Subversion. Although not necessary
to follow this book, knowledge of Subversion will come in handy while
deploying your application, installing third-party plug-ins, and submit-
ting patches to Rails itself if you decide to contribute to Rails.

1.6 Creating a Rails App


The best way to learn Rails is to actually make something, so we are
going to do just that. We will dive right into creating a small Rails

4. http://subversion.tigris.org/
Another Random Document on
Scribd Without Any Related Topics
for in Ely Central, a property that is sandwiched in between the very
best ground of the Nevada Consolidated, is bordered by the Giroux
and occupies a strategic position in the great Nevada copper camp
of Ely, birthplace of what is probably the greatest lowest-cost
porphyry copper mine of America.

By invading the Ely territory as promoter and annexing Ely Central,


the Scheftels corporation committed what was probably, to the
interests among whom our publicity work had wrought greatest
havoc, an unpardonable crime. We butted into the very heart of the
game, and became a disturbing factor in their mining operations.

The Ely Central property consists of more than 490 acres. Years
before, in the early days of the camp, it had been passed over by
the geologists and promoters who selected the ground for the
Nevada Consolidated, Giroux and Cumberland-Ely, because it was
covered by a non-mineralized formation called rhyolite. As
development work progressed and the enormous value of the
surrounding mines was disclosed, it dawned on their owners that
they might have made a mistake and that it would be just as well to
obtain possession of the Ely Central property.

The ground was especially valuable to the Nevada Consolidated, if


for no other reason, as mere acreage to connect up and make
compact the properties owned by them. The second demonstration
of their bad judgment was the fact that, having planned to mine the
Copper Flat ore-body by the steam-shovel method, they overlooked
the value of the Ely Central property as affording them the only
practical means of access to the lower levels of that pit for operation
by the steam shovels.

Investigation had disclosed to me that the evidence which had been


adduced by mine developments on neighboring properties was all in
favor of copper ore underlying the Ely Central area. The rhyolite,
which covered Ely Central, was a "flow," covering the ore, and not a
"dyke," coming up from below and cutting it off.
Why was the property idle? Inquiry revealed that the Ely Central
Copper Company was $89,000 in debt, and that a pre-panic effort to
finance the corporation for deep mine development had failed. The
panic of 1907-8 had crimped the promoters and they could not go
ahead.

The Scheftels corporation entered into negotiations with the Pheby


brothers and O. A. Turner, who held the control, for all the stock of
the Ely Central company that was owned by them. During the
progress of negotiations, early in July, 1909, I heard that the
Guggenheims and W. B. Thompson were very much put out to learn
that the Scheftels company was about to finance the company. They
had belittled the value of the property, as would-be buyers are prone
to do the world over.

Before I entered upon the scene the Pheby brothers had found
themselves objects of persistent and mysterious attacks. Their credit
was assailed in every quarter and they found themselves ambushed
and bushwhacked in every move they made. They were forced into a
position where it was believed they would accept anything that
might be offered them for their interest in Ely Central. As fate would
have it, the Scheftels company entered the race at this psychological
moment.

Summed up, the Scheftels company actually contracted for


1,280,571 shares out of 1,600,000, which represented the increased
capitalization for a total sum of $1,158,916, or at an average price of
90½ cents per share. The time allowed for the payment of all the
money was nine months, stipulated payments being agreed upon at
regular intervals in between. The immediate effect of the
arrangement was this: A dormant property, in debt and lying fallow,
was metamorphosed into a going concern with good prospects of
soon becoming a proved great copper mine, with an assured income
to defray the expenses of deep mine development on a large scale,
and a market career ahead of it that might be expected to match
any that had preceded it in the Ely district from the standpoint of
public interest.

During the progress of the negotiations the stock sold up to $1 per


share. The selling for Philadelphia account of a large block of stock
in the open market dropped the price back, of a sudden, to 50 cents.
The Scheftels company bought stock on this break and urged its
customers to do likewise. On the day the deal was concluded the
market had rallied to 75 cents. Fully six weeks before the deal was
arranged the Scheftels Market Letter and the Mining Financial News
had begun to urge the purchase of the stock. The Scheftels
organization was not hoggish. The establishment was willing that the
public should get in on the cellar floor. There were nearly 300,000
shares outstanding, which the Scheftels corporation had not
corralled in its contract.

Readers of the Market Letter and the Mining Financial News fell over
one another to get in on the good thing. Therein they were wise. By
early September the price had advanced in the market to $1. The
Scheftels publicity was strong in favor of the stock. But it had not yet
put on full steam. It was waiting for an engineer's report to make
doubly sure it was right.

Col. Wm. A. Farish, a mining engineer of many years' experience and


a man with a high reputation throughout the whole of the Western
mining country, had been sent by the Scheftels company to make a
report on the Ely Central. Years before Colonel Farish had reported
on the Nevada Consolidated properties and outlined the very
methods now being used for recovering its ores. But Colonel Farish
had been ahead of his time, and the capitalists in whose interest he
was acting were not prepared for such a radical step in advance of
the then-existing methods, nor to believe that copper ores of such
low grade could be mined at a profit, especially 140 miles from the
nearest railroad. Times and conditions changed, and the 140 miles
were spanned by a well-equipped rail connection.

Colonel Farish's opinion verified our fondest expectations. The report


set forth that the mine possibilities of Ely Central were nearly as
great as those of the Nevada Consolidated itself. On the basis of this
report, which was made in September, the project acquired a new
significance. Development operations were undertaken to prove up
the ground in an endeavor to demonstrate the existence of the
33,000,000 tons of commercial porphyry ore which Colonel Farish
indicated in his report would likely be found within the boundaries of
the southern part of the Ely Central property.

The prospect fairly took the Scheftels organization off its feet. We
were dazzled. We saw ourselves at the head of a mine worth
$25,000,000 to $40,000,000. No time was lost in organizing a
campaign to finance the whole deal. Having no syndicated multi-
millionaires to back it up, the Scheftels corporation went to the
public for the money, the same as hundreds of other notable and
successful promoters had done. The ensuing publicity campaign to
raise capital has been described in hundreds of columns of
newspaper space as one of the most spectacular ever attempted in
Wall Street.

I had absolute faith in the great merits of Ely Central, a faith that
has not been dimmed in the slightest degree by the vicissitudes
through which the company, the Scheftels corporation, and myself
personally have passed. Within thirteen months the Scheftels
corporation caused to be spent for mine development more than
$150,000, and on mine and company administration an additional
$75,000. When the Scheftels company was raided by the
Government on September 29, 1910, and a stop put to further work
the expenses at the mine had averaged for the nine months of that
year above $15,000 a month. Work was going on night and day.
Every possible effort was being made to prove-up the property in
short order. Core-drills sent down from the surface had already
revealed the presence of ore at depth, and I am sublimely certain
that another month or two would have put the underground air-drills
into contact with a vast ore-body identical in quality and value with
that lying on either side in Nevada Consolidated acreage.

Ely Central was the New York Curb sensation in 1909-1910. I used
the publicity forces which had been so successful in protecting the
public against the rapacity of multi-millionaire mining-wolves to
educate them up to the speculative possibilities of Ely Central.

Up went the price. Between the first of September and the middle of
October the market advanced to $2 3-8. On October 13th advices
reached us that 30 per cent. copper ore had been struck in the
Monarch shaft. The Monarch is an independent working, far
removed from the area that is sandwiched in between the main ore-
bodies of the Nevada Consolidated. We were highly elated. The
prospect looked exceedingly bright to us, and there was no longer
any hesitation in strongly advising our following to take advantage of
an unusually attractive speculative opening.

The market boomed along in a most satisfactory way. By October


26th the price reached $3; on November 3d it was $4 a share, and
three days thereafter $4¼ was paid.

The expenses of the Scheftels company on publicity work at this


time amounted to about $1,000 a day. Money for mine development
on Ely Central was being spent as fast as it could be employed. We
were trying to sell enough stock at a profit over the option price to
defray the publicity expenses, keep the mine financed, and meet our
payments on the option, but no more. We were not making any
effort to liquidate on a large scale, a fact which was reflected in the
advancing quotations.
When the price of Ely Central hit $4 in the market, the Scheftels
company rated itself as worth from $3,000,000 to $4,000,000. I had
visions of leading the Guggenheims and Lewisohns and Thompsons
up the Great White Way with rings in their noses. Nat. C. Goodwin,
who had a 25 per cent. interest in the Scheftels enterprise, enjoyed
similar visions, only his fancy ran to building new theaters for all-star
casts.

While Ely Central stock was going skyward and all the speculating
world was making money in it, our publicity forces were busily
driving the bald facts home regarding La Rose, Cumberland-Ely,
Nevada-Utah and other pets of the mighty. Our batteries never let
up for a moment. These various attacked interests were getting
ready to strike back. If their movements had been directed by an
individual general they could not have worked with more community
of interest. One day the sky fell in on us. The plans had been
beautifully laid for our complete ruin. That we escaped utter
annihilation was almost a miracle.

On Wednesday, November 3d, the result of our market operations on


the New York Curb was that we quit long on the day nearly 8,000
shares of Ely Central at an average price of $4. On the same day our
customers ordered the purchase of nearly twice as much stock as
they ordered sold. This indicated to us that the Curb selling was
professional. There was nothing very remarkable about this
performance because brokers doing business on the Curb very
frequently play the market for a fall.

On Thursday, the day following, the Scheftels company was again


compelled to purchase stock on the Curb in excess of sales to the
extent of 7,600 shares, while on the same day the buy orders of
house customers exceeded their orders to sell at least three to one.
The professional selling was now accompanied by rumors on the
Curb which spread like the smell of fire that trouble of some dire sort
was pending for the Scheftels company. Most of this emanated from
an embittered brokerage quarter and we paid little attention to it.

On the succeeding day, Friday, November 5th, the professional


selling was quieted to a point that compelled the Scheftels company
to go long of only 6,600 shares on the day in its Curb market
operations. The purchase of so small a block of stock excited no
suspicion in the Scheftels camp, although it should have, because
Scheftels' customers on this day purchased more than four times as
much stock as they ordered sold, pointing conclusively to a great
public demand and much shorting by professionals.

Then came the coup de main.

THE ASSAULT ON ELY CENTRAL

The 6th day of November fell on a Saturday. The New York Sun of
that morning published under a scare head a vicious attack on the
Ely Central promotion. The attack was based on an article which was
credited in advance to the Engineering & Mining Journal and
appeared in the Sun ahead of its publication in that weekly. The Sun
had been furnished with advance proofs. The Ely Central project was
stamped as a rank swindle. Everybody identified with it was raked
over and I, particularly, was pictured as an unprincipled and
dangerous character, entirely unworthy of confidence and at the
moment engaged in plucking the public of hundreds of thousands. It
was stated that the Ely Central property had been explored in the
early days of the Ely camp and found of no value whatsoever from a
mining standpoint. The Scheftels corporation was accused of setting
out in a cold-blooded way to swindle investors on a bunco
proposition.

I was in my apartment at the Hotel Marie Antoinette at 9 A.M. when I


read the Sun's story. The Scheftels company had thrown $85,000
behind the market during the three preceding market days to hold it
against the attack of professionals.

I called the Scheftels office on the 'phone and gave instructions that
a certified check for $40,000 be sent to Wasserman Brothers,
members of the New York Stock Exchange, with orders to purchase
10,000 shares of Ely Central at $41/8, which was the quotation at the
close on the afternoon before. Orders to buy 15,000 shares more at
the same figure were distributed among other brokers. The single
order was given to Wasserman Brothers because I thought it good
strategy. They are a house of undoubted great responsibility and it
seemed to me that their presence in the market on the buying side
would have an excellent tonic effect.

During the two hours' session I held the 'phone, receiving five
minute reports from the scene of action. Mr. Goodwin was at my
side. At ten minutes to twelve the brokers had reported the
purchase, on balance, of 24,225 shares. Had they purchased 675
shares more they would have completed the orders that were
outstanding and it would have been up to me to decide whether to
lend further support or not. By that time my figures showed that the
Scheftels corporation had thrown behind the market $200,000 in
four days to hold it and I was beginning to have "that funny feeling."
During the last few minutes of the Saturday Curb session the selling
ceased and it seemed that possibly my fears were unfounded.

On Sunday, the 7th, my hopes went a-glimmering. All the New York
papers featured scathing articles, using as authority the Engineering
& Mining Journal's attack, which had appeared on the previous
afternoon. Dispatches indicated, too, that the papers of Boston,
Chicago, Los Angeles and San Francisco had played it up on the
front page as the most shocking mining-stock scandal of the century.

By Monday, the whole country had been plastered with the


sensation. Of course my early Past, all of which was a family affair
and had transpired fourteen years prior, long before I essayed to
enter the mining promotion field, was dragged out of the skeleton-
closet. It lent verisimilitude to the stories.

After reading the Sunday newspapers, I grasped the meaning of the


move and marshalled our forces. It was plain that we had been
marked for the sacrifice. It looked as though we hadn't a chance in a
million of weathering the onslaught if we lent the market further
support. There were about 500,000 shares of Ely Central in the
public's hands, and, without close to $2,000,000 in ready cash to
throw behind the market, we could not be certain of staying the tide.
We didn't have anything like that sum. Personally I did not give up
the fight, but the outlook was mighty blue.

All day Sunday trusted clerks of the Scheftels company worked on


the books, making a statement of the "stop-loss" orders and "good-
till-cancelled" orders of customers. On Monday morning the
newspapers contained aftermath stories of the Engineering & Mining
Journal's arraignment. The air was surcharged with the impending
calamity.

THE CLASH OF BATTLE

With a line of defense carefully outlined, I approached the fray. First,


the Scheftels corporation placed with reliable brokers written orders
to sell at the opening the stocks that were specified in the stop-loss
and good-till-cancelled orders of customers. Not an order to sell a
share of inside stock was given. It was also decided not to place any
supporting orders until after the market opened and it could be
determined with some degree of accuracy what the volume of stock
amounted to that was pressing for sale.

Just before the market opened I could see from my office window a
dense crowd of brokers assembled around the Ely Central specialists.
Although ominously silent, they were struggling for position and
were tensely nervous. It was plain that the over-Sunday anti-
Scheftels newspaper publicity had racked Ely Central stockholders
and created a panicky movement to liquidate, which was about to
find vent in violent explosion. It was evident that the Scheftels
corporation would have to conserve every resource if the day was to
be saved.

The market opened. Instantly there was terrific action. Hundreds of


hands were waving wildly in the air. Everybody wanted to sell and
nobody wanted to buy. The chorus was deafening. Screams rent the
air. The tumult was heard blocks away. Every newspaper had a man
on the spot. Brokers from the New York Stock Exchange left their
posts and came to see the big show; the Stock Exchange was half
emptied. The spectacle had been advertised widely and everybody
was keenly awake and wrought up to a high pitch of excitement over
what had been scheduled to occur.

Had the Scheftels brokers been supplied with orders to buy one-
quarter of a million shares of stock at the closing market price of the
Saturday before, $4 1-8, it was very apparent that they would have
been unable to hold the market. The opening sale was at $4.
Downward to the $3 point the stock traveled, breaking from 25 to 50
cents between sales. Through $3 and on down to the $2 point the
price crashed. Blocks of 10,000 shares were madly thrown into the
vortex of trading. The Curb was a struggling, screaming, maddened
throng of brokers. Every trader appeared to be determined to crush
the market structure. At $2 a share there was a temporary check in
the decline, but the bears renewed their onslaught, gaining
confidence by the outpour of selling orders. Within less than an hour
after the opening the stock hit $1 1-2 a share. At this juncture the
Scheftels broker in Ely Central reported that he had executed all the
stop-loss and good-till-cancelled orders entrusted to him with the
exception of 19,000 shares.
"The Scheftels company will take the lot at $1 1-2," I said.

In lending succor at $1 1-2 per share I was really stretching a point,


although at this figure the net market shrinkage of the Ely Central
capitalization was in excess of $3,000,000. This melting of market
value was awful to contemplate. On the other hand the newspaper
agitation was unmitigated in its violence, stockholders were
convulsed, a break of serious proportions was certain, and it was up
to me to conserve every dollar. The moment the Scheftels bid of
$1.50 a share made its appearance on the Curb and the selling from
the same source for the account of customers was discontinued, it
was seen that the force of the drive had spent itself, at least for the
time being. Support now came from the "shorts." They started to
cash their profits on their short sales of the days previous. Crazed
selling was transformed to frantic buying.

The scene at this juncture was dramatic. It was the momentary


culmination of a cumulative, convulsive cataclysm. In refraining from
selling for its own account the Scheftels corporation violated one of
the sacred rules and privileges not only of the New York Curb but of
the New York Stock Exchange. In both of these markets it is the
custom, where brokers have advance information of an impending
calamity, to beat the public to the market and get out their own lines
first, leaving customers to take care of themselves.

By deftly feeding stock to bargain hunters and to the "shorts" at


intervals and buying stock when it pressed for sale from frightened
holders at other periods the Scheftels company was able to support
the market that afternoon to a close with sales recorded at $2 a
share. The cash loss of the Scheftels company on its Curb
transaction in Ely Central that day was $60,000. This fresh sacrifice
was needed to steady the market.

Tuesday, the following day, the daily newspapers belched forth


further tirades of abuse and calumny. The market crash in Ely
Central was held up to the public as proof positive that the project
was a daring swindle. The raid on the stock in the market was
renewed. A Johnstown flood of liquidation ensued. Fluctuations were
violent. Opening at $2, the price was forced down to $1. It afterward
rebounded to $2, but the waters would not subside, the stock was
hammered again and it closed at $1 per share. To meet the
oncoming emergencies the Scheftels corporation was obliged to
fortify its cash reserve in the only one way that offered. It was
compelled to convert a large part of its reserves of securities into
cash and it had to sell on a declining market. Many accounts were
withdrawn by timid customers, and the Scheftels company was
further called upon to give stability to Rawhide Coalition and Bovard
Consolidated, other stocks which it had been sponsoring in the
markets. Loans were called by brokers with whom the Scheftels
company was carrying stocks, deliveries were frantically tendered to
the Scheftels company of stocks it had purchased at previous high
levels, and a financial onslaught made generally that would
undoubtedly have sunk the Scheftels' ship but for the fact that we
had backed-up in the nick of time, had measured our distance, had
gone just so far and not too far, and had kept on the firing-line.

An exceedingly gratifying feature of the sensational day was the way


in which our friends stood by us. The venom and selfishness of the
overwhelming assaults that had been made upon us convinced many
of the public that we were being made the victims of a special
attack, and with the natural impulse that governs honorable men
they gave testimony to their confidence in us.

On Wednesday the campaign terminated. Ely Central weakened an


eighth from the $1 point, the closing of the day before, recovered to
sales at $1¾ and closed at $1½ bid; $15/8 asked.

All day long our offices were thronged with newspaper reporters and
with pale-faced and agitated customers. Our clients felt their
helplessness in such a tumult of warring forces. The only thing they
could do was to stand by and watch developments as the battle
waged. It was a proud moment for me when, at the end of the day's
market, I mounted the platform in the Scheftels customers' trading-
room, gave voice to a shrill cheer of triumph and wrote on the
blackboard the following:

"We have not closed out a single margin account! We are carrying
everybody!"

The scene which followed warmed the cockles of my heart. I was


literally mobbed, but it was a friendly mob. We all joined in a season
of noisy rejoicing. That we should have been able to survive the
three-days' siege with minimum losses to customers and without
sacrificing a single margin account was a signal achievement. I
doubt if there are many cases like it in the history of Wall Street.

Scores of telegrams were received from out-of-town customers to


whom the margin respite was wired. One of these read:
You may look for a tidal wave of business. Your princely
action warrants 21 guns for the House of Scheftels.

Another one was to this effect:

The whole situation was greased for your descent. It was a


shoot-the-chutes and a bump-the-bumps proposition.
Congratulations on your survival.

Hundreds of letters of a similar tenor poured in upon us. Many of


these came from the camp of Ely itself, where large blocks of the
stock were held by mining men on the ground.

Thursday the stock closed at $1¾; Friday it advanced to sales at


$17/8 and hung there.

The Scheftels organization now drew its first long breath. Friends
and enemies alike marveled how the corporation had managed to
survive. We had held the fort, but at murderous cost.

I got busy with the publicity forces at my command. Through the


Scheftels Market Letter and the Mining Financial News the story was
told of the whole dastardly campaign.

The Weekly Market Letter of the Scheftels company on November


13, 1909, devoted 24 columns to the story of the raid.

That the Guggenheim-managed Nevada Consolidated was well


pleased with the publication of the Engineering & Mining Journal's
attack seemed clear to me. The reason was this: In its attack the
Engineering & Mining Journal stated that two drillholes put down by
the Nevada Consolidated in the immediate vicinity of Ely Central had
failed to show better than nine-tenths of one per cent. copper ore
which, the article said, was below commercial grade. (At this late
date, October, 1911, they are mining ore in the steam-shovel pit of
the Nevada Consolidated that will not average more than eight-
tenths of one per cent. copper transporting it to the concentrator,
more than twenty miles away, and treating it at a profit. But this is
not the point.) An engineer of international prominence telegraphed
the Scheftels company from Ely as follows:

Two drill holes mentioned in Engineering & Mining Journal


article were completed only last week. Results must have
been telegraphed to New York.

These holes gave great trouble on account of caving


ground. I heard drill runners say they were stopped on
that account and were in ore in bottom. In any case, it is
not conclusive of unpayable ore in vicinity. This condition
often occurs.

I could write a book in reply to the Engineering & Mining Journal's


tirade, showing the utter flimsiness of the statements it made.
Limited space forbids anything more than an outline.

Charles S. Herzig was employed to report confidentially on the


property. Mr. Herzig's report was later checked up by Dr. Walter
Harvey Weed, a great copper geologist of known high standing who
was formerly one of the principal experts of the United States
Geological Survey and was himself a frequent contributor to the
Engineering & Mining Journal. Dr. Walter Harvey Weed wired to the
C. L. Constant Company, the metallurgists and mining engineers,
from Ely, as follows:

After making a most thorough examination my opinion is


Southern part Ely Central property is covered by rhyolite
capping. Geological evidence demonstrates that the
porphyry extends eastward (through Ely Central) from
steam-shovel pit and with excellent chance of containing
commercial ore beneath a leached zone. A well defined
strong Fault separates steam-shovel ore from rhyolite area
and this Fault Plane may carry copper glance (very rich
copper ore) of recent origin, due to descending solutions.
The iron-stained jasperoid croppings in the limestone areas
give promise of making ore in depth on Ely Central
property as they do in Giroux.

The Engineering & Mining Journal said in its article that the northern
portion of Ely Central showed the Arcturus limestone of the district.
It stated that in this limestone at various places there is a little
mineralization but never during the history of the district were any
profitable results obtained. As against this, Engineers Farish, Herzig
and Weed reported that the limestone areas on Ely Central would
likely show the presence of mines. As a matter of fact, Giroux,
neighbor of Ely Central, had sunk through this limestone and opened
one of the richest bodies of copper ore ever disclosed.

The Engineering & Mining Journal said that in representing that pay
ore is likely to exist in the area of Ely Central sandwiched in between
the two big mines of Nevada Consolidated, the Scheftels company
was practicing deception. Not only did Messrs. Farish, Herzig and
Weed report in favor of the likelihood, but it is now a commonly
accepted fact that, unless all known geological indications are
deceptive, Ely Central has the ore in this stretch of territory. A report
made as late as September, 1911, by engineer Richard T. Pierce, for
the reorganization committee of Ely Central, expresses the opinion
that an area 1,300 feet by 1,900 feet at the south-east end of the
Eureka workings "will be found to contain mineralized porphyry, with
reasonable assurance that commercial ore will be had in it."

Mr. Herzig's first telegram from Ely after examining the Ely Central
property was to this effect:
There is no question that the rhyolite was deposited in Ely
Central after the enrichment of the porphyry. The Fault
that limits the rhyolite in the Nevada Consolidated pit is
indicated by several feet thickness of crushed mineralized
porphyry-rhyolite ore, which is a positive evidence that the
porphyry was enriched before the faulting. The limestone
and contact areas owned by the company, in my opinion,
have great potential value. The indications are in every
way similar to Bisbee. Rich carbonate ore has been
encountered on the Clipper and Monarch claims of Ely
Central and I look forward to seeing big ore bodies opened
up at these places.

Reports of both these engineers, many thousand words in


length, made later, confirm these messages.

What probably convinced me more than anything else of the


inaccuracy of the statement regarding the Ely Central property by
the Engineering & Mining Journal was the attitude of Charles S.
Herzig. He is my brother.

Up to within thirty days of the appearance of the attack in the


Engineering & Mining Journal I had not set eyes on him in fifteen
years. A graduate of the Columbia School of Mines, he had in the
interim examined mining properties in South Africa, Egypt, Australia,
the East Indies, Siberia, every European country, Canada, Mexico,
Central America, South America and the United States in the
interests of some of the world's greatest financiers. These expert
examinations had covered deposits of gold, silver, copper, lead, zinc,
coal and other minerals. In the engineering profession he is known
as an expert who has his first failure yet to record. His standing is
unquestioned as an engineer and a mine-valuer.

I had heard some criticism of the Farish report, made by engineers


of the modern school, in which it was pointed out that Colonel Farish
had failed to give scientific reasons for all of his deductions. I asked
Captain W. Murdoch Wiley, then a member of the C. L. Constant
Company, assayers, metallurgists and mining engineers, whether he
could induce my brother to make an examination. I did not approach
Charles myself, because we had been estranged. So it was that
when he returned from Europe after an absence of many years, he
had not even looked me up. Captain Wiley arranged for a meeting at
the Engineers' Club. I went there, and was formally introduced by
Captain Wiley to my brother across a table.

"What will you take to make a report on Ely Central?" I asked in the
same matter-of-fact way I would have addressed a stranger.

"What's the purpose of the report?"

"The Scheftels company wants confidential, expert information such


as you are qualified to give as to the value and prospects of the
property," I answered.

"I'll take $5,000," he said, "but only on one condition. I am going to


the Ely and Ray districts to report for English capitalists, and I can
take your property in at the same time. My report is not to be
published and I reserve the right to make a verbal instead of a
written one. If you really want to know what I think of the property,
I am quite willing to give it a careful examination and let you know.
Because of the stock-market campaign you are making, I would not
accept your offer if, did I report favorably, your idea would be to
make use of the report in the market."

The bargain was struck. A few days later Mr. Herzig received $2,500
from the Scheftels company, on account, and a check for traveling
expenses. He left for Ely.

On the Saturday morning when the New York Sun article appeared
containing the excerpts from the Engineering & Mining Journal's
onslaught, I wired my brother substantially as follows:
Savage attack in Engineering & Mining Journal on Ely
Central. If your report on property is favorable, I beg you
to let us have it by wire and allow the use of it to
counteract.

An hour later I followed it up with another message telling him not


to wire any report. I set forth that because he was my brother, it
might prove of little avail, now that the publication had been made,
and that it might only tend to do him personal damage in the
profession because of the unqualified manner in which the
Engineering & Mining Journal had taken a stand against the
property. In reply he wired Captain W. Murdoch Wiley the short but
decisive report already quoted herein, regarding the geological
reasons why Ely Central should have the ore, which afterward was
fully verified by Dr. Walter Harvey Weed in the message also
reproduced in the foregoing. In a letter from Ely to Captain Wiley
confirming the message, the original of which is in my possession,
Mr. Herzig said:

I have formed a very favorable opinion of the property. I


feel that it has the making of a big mine, and under the
circumstances I am willing to stand a little racket for a
time.

The same day he wired Captain Wiley to buy for his account 2,500
shares of Ely Central at the market price, which order was executed
through the Scheftels company.

Editor Ingalls of the Engineering & Mining Journal and my brother


had been friends for years. My brother had been employed early in
his career by the Lewisohns, Guggenheims and the Anaconda
Copper Company, and later in Europe, Australia and India by mine
operators of even higher class. Up to the time when the Engineering
& Mining Journal's attack appeared he had not committed himself on
Ely Central. When he did commit himself it was with the
foreknowledge that in doing the unselfish and courageous thing his
name would be besmirched if under development Ely Central turned
out to be what the Engineering & Mining Journal had declared
probable. In that event his relationship with me would be held up as
positive proof of duplicity and it would look bad for him. The fact
that under all these circumstances he jumped into the breach
satisfied me that the attack of the Engineering & Mining Journal was
unjustified.

A BOMBSHELL IN THE ENEMY'S CAMP

As soon as the Scheftels corporation was able to obtain a copy of


the corroborative report of Dr. Walter Harvey Weed, which the great
copper geologist made to the C. L. Constant Company, it filed a libel
suit against the Engineering & Mining Journal for $750,000
damages. Simultaneously Mr. Scheftels filed another suit for an
additional $100,000 in his own behalf.

The filing of the Scheftels libel suits against the Engineering &
Mining Journal was a bombshell. It was formal notice to the forces
arrayed against us that we did not propose to be made victims of an
unholy hostility and that we were determined to proceed along old
lines and not abate in the slightest our wide-open publicity
measures. It was also noticed that we proposed to go through with
the Ely Central deal.

After it became evident that we intended to keep on fighting, the


Scheftels offices were openly visited and inspected in detail one day
by the late Police Inspector McCafferty. In a bullying manner this
police official let it be known that we were in official disfavor with
him. His manner could hardly have been more offensive if he had
been invading a den of counterfeiters. Mr. McCafferty did not specify
just what he was after or just what he expected to find, but he
made it plain to us that we were marked and that he had it in for us.
He stalked scowlingly through the entire establishment and made
vague threats of what was in store for us.

Late that night I learned that the Inspector had invaded the living-
rooms of my associate, Nat. C. Goodwin, where he delivered himself
somewhat as follows:

"What are you fellows trying to do, anyway? What are you trying to
put across on us? Do you think we are going to stand for any such
newspaper notoriety as you are getting and watch it with our arms
folded? Do you think we are fools or crazy, or what? I want you to
understand that you fellows have got your nerve with you. Get busy
or the police will be on your backs to-morrow!"

I told Mr. Goodwin that our enemies had evidently sicked the
Inspector on to us, but that I didn't think any action would be taken.
We were victims and not culprits, and unless, indeed, the United
States was Russia, nothing untoward could happen.

I promised Mr. Goodwin, however, that I would attend to the matter


without delay. I laid all of the facts regarding the newspaper attack
before a prominent citizen who promised forthwith to convey the
information in person to the Inspector or one of his superiors. He did
so. That was the last we heard of the matter.

The Engineering & Mining Journal's lawyers addressed themselves to


customers of the Scheftels company, who had lost money in the
market break in Ely Central from $4 to $1.50. By letter they urged
them to send on a full statement of facts and suggested that they
might be of service, and without charge.

Letters of this character were sent to large numbers of our


customers, many of whom simply sent them to us. In some cases,
however, customers who had read the attack in the Engineering &
Mining Journal or quotations from it in widely circulated daily
newspapers, needed but the letter from the lawyers to induce them
to come forward with a complaint.

On the whole, this fishing expedition must have been something of a


water-haul and a disappointment, for the attorneys of the
Engineering & Mining Journal.
The Post-office Department at New York, in January and February,
sent letters broadcast to readers of the Scheftels Weekly Market
Letter, asking whether the business carried on was satisfactory—the
usual form that is used where a firm is under investigation. Scores of
these letters were forwarded to us by customers with remarks to the
effect that evidently "somebody was after us." An inquiry of this sort
is calculated to do terrible damage to the reputation and standing of
any house that does a quasi-banking business. Our attorneys
complained to Inspector Mayer of the New York division of the Post-
office that an injustice was being done. No more letters of the
character described were sent out, because the early replies that
were received by the Inspector to his circular letter brought forth no
serious complaints. However, it was afterward disclosed that the
investigation did not cease here and that the Post-Office Department
continued to conduct a searching inquiry only finally to abandon its
enterprise.

Enters upon the scene an associate of the Engineering & Mining


Journal's lawyers defending that publication against our suit for libel.
He called at the Scheftels offices and demanded from Mr. Scheftels
information with regard to the account of C. H. Slack of Chicago. He
got it. It showed that Mr. Slack had purchased 50,000 shares of
Bovard Consolidated at 10 cents per share, for which he had paid
cash, and that Mr. Slack had purchased an additional 100,000 shares
at 14¼ and 14¾ cents per share; and that Mr. Slack had refused,
after the market declined to below the purchase price, to pay the
balance due, because of delayed delivery.
The delay in delivery was accidental. The Scheftels company actually
had in its possession two million shares of the stock or more, and
the delivery would have been tendered earlier but for the fact that
the raid on Ely Central had piled up so much work for the clerical
force that everything was set back. We knew of no legitimate excuse
for Mr. Slack, because he could have ordered the stock sold at any
time, delivery or no delivery. The Slack transaction receives
amplification here, because later, when the Scheftels corporation
was raided by a Special Agent of the Department of Justice, it
figured as one of the cases cited by the Agent in the warrant sworn
to by him against B. H. Scheftels & Company as proving the
commission of crime.

Another case about which Mr. Scheftels was asked to give full
information was that of D. J. Szymanski, a corn doctor at 25 Broad
Street. Mr. Scheftels had urged the Doctor to buy Ely Central when it
was selling at 75 cents before the rise. Later, when the advance was
well under way, above the $3 point, the Doctor bought some stock
through the Scheftels corporation. When the price hit $4 he was
urged to take profits. He refused to do so. When the attack began
and the price broke badly the Doctor saw a big loss ahead.

He called at the Scheftels' office and begged for the return of the
money he had lost in his Ely Central speculation.

The investigation was heralded among the brokers and caused much
market pressure on the stocks fathered by the Scheftels company.
We were not dismayed. To strengthen our position and to give
added token of our good faith we increased our development
operations at the mines. Our expenses in that quarter were swelled
to the limit of working capacity on our underground explorations, as
I realized that our salvation might depend on making good in quick
order with Ely Central from a mining standpoint. We knew the ore
was there and that it was up to us to get it before our enemies got
us.
A GOVERNMENT RAID IS RUMORED

Out of a blue sky late in the month of June came news to the
Scheftels office that a newspaper reporter on the New York
American had stated that he had seen a memorandum in the city
editor's assignment-book to watch out for a Scheftels raid by the
United States Government. The information was reliable and it gave
us a shock. Yet the thought that the powers of a great government
like the United States could be used to crush us without giving us a
hearing seemed unbelievable.

To be on the safe side Mr. Scheftels, accompanied by an attorney of


high standing, visited Washington. They went direct to the
Department of Justice, where Attorney-General Wickersham's private
secretary, after a friendly conversation, referred them to the chief
clerk. He reported, after a search of twenty-five minutes' duration,
that there was no charge against B. H. Scheftels & Company. He
even volunteered the information that he did not know that such a
firm was in existence.

It afterward developed that at the very time Mr. Scheftels and the
attorney were at the Department of Justice a special rubber-shoe
investigation was on under the dual direction of a young Washington
lawyer on Attorney-General Wickersham's personal staff, and a
Special Agent of the Department of Justice. The latter had been
given extraordinary powers as a special agent of the Department of
Justice, ostensibly to "clean out Wall Street."

Satisfied they were in the wrong place, Mr. Scheftels and the
counsellor departed from the Attorney-General's office for the Post-
Office Department. They were referred to Chief Inspector Sharp. The
lawyer requested that the Scheftels corporation be given a hearing
before any action was taken on any complaints that might reach the
department. Mr. Sharp agreed to this on condition that the attorney
would agree for the Scheftels company that an inspection of the
books of the corporation would be permitted on demand at any
time. There was a ready assent. A memorandum to this effect was
left with Inspector Sharp.

Mr. Scheftels left the Department with positive assurance that no


snap judgment would be taken. Edmund R. Dodge of Nevada,
personal counsel of B. H. Scheftels & Company, then addressed a
letter to U.S. Senator Newlands with the request that he take the
matter up direct with the Postmaster-General.

Senator Newlands, under date of July 2, wrote Mr. Dodge that he


had addressed a letter to the Postmaster-General with the request
that notice be given to Mr. Dodge in case any complaint or
information was lodged against the Scheftels corporation. A few days
later Senator Newlands sent Mr. Dodge a letter from Theodore
Ingalls, Acting Chief Inspector of the Post-Office Department, in
which Mr. Ingalls said it was the practice of the Department in case
of alleged use of the mails for fraudulent purposes to give individuals
against whom complaint has been made full opportunity to be heard
either through person or counsel, should adverse action be
contemplated as a result of the investigation of such allegation.

Feeling that our house had been securely safeguarded against


surprise parties, I at this junction took a trip to Nevada, where
urgent business matters required my attention. While I was in the
West telegrams were sent me that the premier mail-order mining-
stock bucket-shop firm on Broad Street was flooding the mail and
burdening the telegraph wires with urgent appeals to stockholders of
Rawhide Coalition, one of our specialties, to sell out their holdings,
as a severe break in the price of the shares was impending.
Forewarned of this attack, I telegraphed instructions from Reno to
meet the onslaught with a notice in the Mining Financial News
addressed to investors, telling them to be on their guard.
My trip to the West made a pocketful of money for investors by my
purchase of the control in the Jumbo Extension company on a
monthly payment plan. The price of the stock tripled in the market.
My re-entrance into the Goldfield camp was especially distasteful to
the Nixon-Wingfield interests. Before I left Goldfield I was actually
warned that the vengeance wreaked on the Sullivan Trust Company
would be visited on the Scheftels company for daring to reinvade the
Goldfield district.

Late in August the Scheftels company endured what was probably


the most severe strain it had been put to since its incorporation. We
had been making heroic efforts to rally the price of our specialties on
the New York Curb market. We were meeting with unusual
resistance from professional sources. At the period of which I
narrate, Ely Central had registered a low quotation of 62½ cents and
we had successfully strengthened it to around $1. All the way up we
met with heavy sales. One day deliveries crowded in so fast that
three cashiers working in the "cage" were unable to keep up with
the transactions. The business of the corporation had been heavy in
the general list as well as in the house specialties. There was more
than sufficient money on hand to finance all the transactions that
day, but not, however, unless deposits were made in bank as rapidly
as our own deliveries were made and collected for by our
messengers.

About 2 o'clock in the afternoon a report reached the Curb that the
bank checks of B. H. Scheftels & Company were not being promptly
certified. As this rumor gained currency the excitement on the Curb
increased. The Curb concluded that we were at last "busted." Motley
throngs began to assemble in front of the offices. The fierce yells of
brokers could be heard bidding for and offering Scheftels checks
below their face value. A throng of the riffraff of the Street swarmed
in front of the building.
One or two individuals, implacable enemies who had repeatedly led
the market onslaught against the Scheftels stocks, offered Scheftels
checks for small sums at as low as 50 cents on the dollar. These
were licked up by our friends who had been assured that we were
financially all right and that some mistake must have been made at
the bank.

Investigation showed that dilatory message service was responsible


for the bank's delay in certifying. Our deposits did not reach the
bank as promptly as they should have. As a special favor to us that
afternoon, while the tumult in front of our doors was greatest, the
bank continued to certify checks until 3:30 o'clock, extending the
closing time 30 minutes. Then they reported that a comfortable cash
balance was still on hand.

The next morning the newspapers started a jamboree. First-page,


last-column, double-leaded, scare-head stories greeted every New
Yorker for breakfast, telling him about the panic among Curb brokers
to sell the Scheftels checks the afternoon before. Needless to say it
was the kind of notoriety that was likely to do greatest injury to the
House of Scheftels. If anything half as bad had been printed about
the strongest bank in New York, that bank would have been forced
to close its doors before the day was half over.

Nor did I for a moment underrate the danger of our position.


Between two suns I managed to assemble $50,000 in addition to our
cash reserves, with promises of as much more as was needed. We
easily held the fort. At the end of the day's business I created a
diversion by appearing in the Scheftels board-room, flourishing a
handful of $1,000 bills before the newspaper men. The scribes found
the Scheftels corporation meeting all demands, and, at the end of
the session, with a small bale of undeposited money in its
possession.

The strain, however, was great. Confidence was again impaired.


Many accounts were withdrawn by customers. We were compelled to
ease our load by selling accumulated stocks at a loss. The price of
Ely Central and other Scheftels promotions dropped. The decline was
assisted by general weakness in other Curb stocks.

Peculiarly enough, at the time when the market for Ely Central
shares was lowest, during the latter part of September, fourteen
months after the Scheftels company had taken hold of the
proposition, mine reports were most favorable. Underground
development work and churn drilling had set at rest for all time the
question of whether or not mineralized porphyry underlies the
rhyolite cap or flow extending eastward through Ely Central ground
from the steam-shovel pit of the Nevada Consolidated. Upward of
$240,000 had been paid out for administration, mine equipment and
for miners' wages to make this demonstration.

The Scheftels company was now informed that the Nevada


Consolidated was actually meditating a trespass on the Juniper claim
of the Ely Central company, in order to secure an outlet from the
lower levels of its giant steam-shovel pit. Warning in writing had
already been served on the Nevada Consolidated officials against
such a course. On September 25th attorneys of the Ely Central
Copper Company secured from a Nevada court an order restraining
the Nevada Consolidated from proceeding with this trespass and
citing it to show cause why it should not cease to trespass on other
Ely Central ground.

The attorney telegraphed to New York that a bond was required


before the injunction could be made operative. On September 27th
and 28th telegrams were exchanged between the Ely Central offices
in New York and the Nevada attorneys of the company at Reno as to
providing sureties for the bond.

The sureties never qualified. A catastrophe befell us and brought to


an earthquake finish the house of B. H. Scheftels & Company and all
its ambitious plans.
The constant turmoil in which the House of Scheftels had found
itself, from the day the Engineering & Mining Journal's attack
appeared, had made it impossible for the Scheftels company to hold
the markets for Ely Central and Rawhide Coalition. Impairment of
credit, money stringency and a general declining market were partly
responsible. But there was another important factor. Because of the
time-limit of its options, the Scheftels company was forced, from
time to time, to throw stock on the market at prices which showed
an actual loss.

It had one market winner which showed customers and the


corporation itself a large profit, namely, Jumbo Extension. I held an
option on approximately 450,000 shares of this stock at an average
price of 35 cents, which I had turned over to the corporation. The
market advanced to 70. Following the tactics employed in Ely Central
at the outset of that deal, the Scheftels corporation had urged all its
customers to buy Jumbo Extension at the very moment when I was
negotiating for the option in Goldfield, with the result that purchases
were made in the open market by readers of our market literature at
from 25 cents up, with accompanying profit-making.

As the price soared, a short interest of 150,000 shares of Jumbo


Extension had developed among brokers in San Francisco and New
York, and it was very apparent from the demands of stock for
borrowing purposes that it would be impossible for the short
interests to cover excepting upon our terms. The Scheftels company
was making ready for a "squeeze" of the shorts such as had not
been administered before in the history of the Curb. At the very
moment of victory, however, when we were making ready to execute
a magnificent market coup in Jumbo Extension in the markets of San
Francisco and New York, we were plunged without warning to
complete ruin.
THE RAID ON B. H. SCHEFTELS & CO.

The destruction of the Scheftels structure was consummated on the


29th day of September, 1910. I was standing on the front stoop of
the Scheftels offices, watching the markets for the Scheftels
specialties. A broker with San Francisco connections made me a bid
of 68 cents for 10,000 shares of Jumbo Extension. I promptly
refused. At that very moment my attention was called to the violent
slamming of a door behind me. Turning to a Scheftels employee who
was standing by my side, I learned that a number of strangers had
filed into the customers' room without attracting any particular
attention. I tried to get in. The door was locked. Undoubtedly
something serious was transpiring. I walked a full block through the
hallway to the New Street entrance of the building where the offices
of the Mining Financial News adjoined those of the Scheftels
corporation. I tried the door there with similar result. It was locked
against me.

That settled it. I concluded that the ax had fallen.

The shock of realization that our offices were being raided by the
Government did not for a moment throw me off my balance or put
fear in my heart, nor did the sense of the outrage affect me at the
moment. There was but one sickening thought—the ruin of the
edifice I and my associates had labored day and night for so many
months to build and the fate of our customers who had invested
their money in the companies we had promoted.

In three seconds I was on my way to the place where I thought


succor could be found—the offices of the Scheftels attorneys. I
walked across the street to the New Street entrance of a building
that extends from Broadway to New Street, ambled across to the
Broadway side, jumped on a surface car, rode three blocks to
Broadway and Cedar Street, jumped into an elevator, and in a few
minutes entered the offices of House, Grossman & Vorhaus.

"Go over to the Scheftels offices," I said, "and be quick! I think we


are being raided."

In a moment two members of the law firm were on their way. Within
ten minutes after the raiders had entered the offices the lawyers
were on the spot. They were denied admittance and had to content
themselves with waiting outside the door until the prisoners were
taken out.

The moment the lawyers left their offices I began to use the 'phones
to provide for the release on bail of the men arrested. I found it
necessary to go in person and so I left the lawyers' offices and
walked down Broadway. My attention was attracted by the clanging
of the bell of the police-patrol wagon. As it wheeled past me on the
run I could see my associates huddled together in the Black Maria
on their way to the bastile.

For the moment, I lost full sense of the gravity of what was
transpiring and was overcome by a feeling of joy that I had been
spared that ignominy. That self-felicitating slant of an intensely
serious situation passed. My associates were in trouble and it was up
to me to help them. I was at large and I knew that I could do more
for my friends and myself by not immediately surrendering.

I returned to the lawyer's office, where I remained. All this time the
thought never entered my mind that we were in any sense guilty of
any intent to defraud anybody, or that we had committed any
offense against law or the rules of fair conduct. The one consuming
and controlling idea in my mind was that somebody had put one
over on us and that it was up to me to organize for defense against
the abominable outrage.
What transpired behind the closed doors while the Scheftels lawyers
were attempting to gain an entrance for the instruction of the
corporation, its officers and employees as to their rights, beggars
description. Gentle reader, you would not conceive the reality to be
possible. Armed with a warrant which conferred upon him the right
to arrest, seize, search and confiscate, the Special Agent of the
Department of Justice had secured from the local police
headquarters a detail of fifteen heavily armed plain-clothes men.

Once inside the Scheftels establishment, the doors were locked and
egress barred. The main body of invaders then took possession of
the front offices, while others searched through the back rooms and
boisterously commanded everybody to remain where they were until
given permission to depart. The establishment was under seizure,
every foot of it, and every person found within its doors was held
prisoner. The Special Agent took pains to impress upon everybody
within hearing that he was in supreme command. Leaving police
guards in the front room, he stalked into the telegraph-cage where
two or three operators were sitting at tables.

Pressing the muzzle of a revolver into the face of Chief Operator


Walter Campbell—a quiet and inoffensive man—the Special Agent
commanded:

"Cut off that connection!"

Mr. Campbell didn't at first see the gun because it was pointed at his
blind eye. When he got his first peep he concluded that a maniac
had invaded his sanctum and he almost expired with apoplexy on
the spot.

Returning to the front office, the Agent entered the cashier's cage
and took possession of the company's pouch containing its
securities.
He gave no receipt to any responsible employee of the Scheftels
company for anything. When Mr. Stone, one of the cashiers,
suggested to him that he was there to safeguard the securities, he
thundered,

"Come out of there!"

"What authority have you for this?" demanded Mr. Stone. The Agent
thereupon showed his badge.

A moment later one of the deputies pried open the cash-drawer. The
Special Agent was at his elbow.

"Oh, look what's here!" cried the deputy.

Thereupon the Agent of the Department of Justice impounded the


contents of the cash-drawer, without counting the cash, checks,
money-orders, etc., or giving any member of our firm a receipt for
them.

Turning to the Scheftels officers and employees who had been


placed under arrest, he ordered them removed from the room.

It was about as raw a performance as was ever witnessed in a


peaceful brokerage firm's banking-room.

Bookkeepers were ordered to close up books. United States mail in


the office was impounded, including mail that had been received in
the office for delivery to others.

The Scheftels employees were commanded to stand in their places


with arms folded. The desperadoes among them—those for whom a
warrant had been issued and who had been jerked out and huddled
together in the outer room—were then searched for deadly
weapons. One penknife and the stub of a lead-pencil were found on
their persons. The deadly knife was hardly sharp enough to serve
the purpose of nail-manicuring. Not one of the men under arrest
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!

ebookname.com

You might also like