Rails for PHP Developers, The Pragmatic Programers (2008).pdf

(12979 KB) Pobierz
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´
c
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
Preface
What Rails Offers
. . . . . . . .
Who Should Read This Book
.
Resources
. . . . . . . . . . . .
PHP and Rails: A Personal View
About the Code Examples
. . .
About the Environment Used
.
Version Requirements
. . . . .
How to Read This Book
. . . . .
10
11
11
12
12
13
14
14
15
15
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
I
1
From PHP to Rails
Getting Started with Rails
1.1
Rails as an Extension of Ruby
1.2
The Components of Rails
. . .
1.3
Opinionated Software
. . . . .
1.4
The MVC Pattern and Rails
. .
1.5
Installing Ruby and Rails
. . .
1.6
Creating a Rails App
. . . . . .
1.7
Chapter Review
. . . . . . . . .
1.8
Exercises
. . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
17
18
18
19
20
22
24
25
42
42
43
43
45
47
48
50
53
57
2
Beginning Ruby Code
2.1
Seeing Ruby as a General-Purpose Language
2.2
Interacting with Ruby
. . . . . . . . . . . . . .
2.3
Objectifying Everything
. . . . . . . . . . . . .
2.4
Accepting Ruby’s Object World
. . . . . . . . .
2.5
Assigning to Variables
. . . . . . . . . . . . . .
2.6
Writing Methods and Passing Parameters
. . .
2.7
Controlling Program Flow
. . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Zgłoś jeśli naruszono regulamin