Learning.Rails.3.pdf

(12442 KB) Pobierz
887401166.009.png
887401166.010.png
Learning Rails 3
Simon St.Laurent, Edd Dumbill, and Eric J. Gruber
Beijing
Cambridge
Farnham
Köln
Sebastopol
Tokyo
887401166.011.png 887401166.012.png 887401166.001.png 887401166.002.png 887401166.003.png 887401166.004.png 887401166.005.png 887401166.006.png
 
Learning Rails 3
by Simon St.Laurent, Edd Dumbill, and Eric J. Gruber
Copyright © 2012 Simon St.Laurent, Edd Dumbill, Eric J. Gruber. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles ( http://my.safaribooksonline.com ) . For more information, contact our
corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
Editor: Simon St.Laurent
Production Editor: Iris Febres
Proofreader: Jasmine Perez
Indexer: Lucie Haskins
Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrators: Robert Romano, Rebecca Demarest,
and Jessamyn Read
July 2012:
First Edition.
Revision History for the First Edition:
2012-07-11 First release
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Learning Rails 3 , the image of the tarpans, and related trade dress are trademarks
of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
ISBN: 978-1-449-30933-6
[M]
1342467902
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
1.
Starting Up Ruby on Rails . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
If You Run Windows, You’re Lucky
2
Getting Started at the Command Line
3
Starting Up Rails
8
Test Your Knowledge
9
Quiz
9
Answers
9
2.
Rails on the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Creating Your Own View
11
What Are All Those Folders?
14
Adding Some Data
16
How Hello World Works
18
Adding Logic to the View
20
Test Your Knowledge
22
Quiz
22
Answers
22
3.
Adding Web Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
I Want My CSS!
23
Specifying Stylesheets
28
Creating a Layout for a Controller
29
Choosing a Layout from a Controller
31
Sharing Template Data with the Layout
33
Setting a Default Page
34
Test Your Knowledge
36
Quiz
36
Answers
36
iii
887401166.007.png 887401166.008.png
Zgłoś jeśli naruszono regulamin