To edit pages or tickets please login with username/password: aaf/aaf

root/trunk/demo/README

Revision 66, 5.9 kB (checked in by jk, 2 years ago)

t

Line 
1 == Welcome to Rails
2
3
4 Rails is a web-application and persistence framework that includes everything
5 needed to create database-backed web-applications according to the
6 Model-View-Control pattern of separation. This pattern splits the view (also
7 called the presentation) into "dumb" templates that are primarily responsible
8 for inserting pre-built data in between HTML tags. The model contains the
9 "smart" domain objects (such as Account, Product, Person, Post) that holds all
10 the business logic and knows how to persist themselves to a database. The
11 controller handles the incoming requests (such as Save New Account, Update
12 Product, Show Post) by manipulating the model and directing data to the view.
13
14 In Rails, the model is handled by what's called an object-relational mapping
15 layer entitled Active Record. This layer allows you to present the data from
16 database rows as objects and embellish these data objects with business logic
17 methods. You can read more about Active Record in
18 link:files/vendor/rails/activerecord/README.html.
19
20 The controller and view are handled by the Action Pack, which handles both
21 layers by its two parts: Action View and Action Controller. These two layers
22 are bundled in a single package due to their heavy interdependence. This is
23 unlike the relationship between the Active Record and Action Pack that is much
24 more separate. Each of these packages can be used independently outside of
25 Rails.  You can read more about Action Pack in
26 link:files/vendor/rails/actionpack/README.html.
27
28
29 == Getting started
30
31 1. Run the WEBrick servlet: <tt>ruby script/server</tt> (run with --help for options)
32    ...or if you have lighttpd installed: <tt>ruby script/lighttpd</tt> (it's faster)
33 2. Go to http://localhost:3000/ and get "Congratulations, you've put Ruby on Rails!"
34 3. Follow the guidelines on the "Congratulations, you've put Ruby on Rails!" screen
35
36
37 == Example for Apache conf
38
39   <VirtualHost *:80>
40     ServerName rails
41     DocumentRoot /path/application/public/
42     ErrorLog /path/application/log/server.log
43  
44     <Directory /path/application/public/>
45       Options ExecCGI FollowSymLinks
46       AllowOverride all
47       Allow from all
48       Order allow,deny
49     </Directory>
50   </VirtualHost>
51
52 NOTE: Be sure that CGIs can be executed in that directory as well. So ExecCGI
53 should be on and ".cgi" should respond. All requests from 127.0.0.1 go
54 through CGI, so no Apache restart is necessary for changes. All other requests
55 go through FCGI (or mod_ruby), which requires a restart to show changes.
56
57
58 == Debugging Rails
59
60 Have "tail -f" commands running on both the server.log, production.log, and
61 test.log files. Rails will automatically display debugging and runtime
62 information to these files. Debugging info will also be shown in the browser
63 on requests from 127.0.0.1.
64
65
66 == Breakpoints
67
68 Breakpoint support is available through the script/breakpointer client. This
69 means that you can break out of execution at any point in the code, investigate
70 and change the model, AND then resume execution! Example:
71
72   class WeblogController < ActionController::Base
73     def index
74       @posts = Post.find_all
75       breakpoint "Breaking out from the list"
76     end
77   end
78  
79 So the controller will accept the action, run the first line, then present you
80 with a IRB prompt in the breakpointer window. Here you can do things like:
81
82 Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
83
84   >> @posts.inspect
85   => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
86        #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
87   >> @posts.first.title = "hello from a breakpoint"
88   => "hello from a breakpoint"
89
90 ...and even better is that you can examine how your runtime objects actually work:
91
92   >> f = @posts.first
93   => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
94   >> f.
95   Display all 152 possibilities? (y or n)
96
97 Finally, when you're ready to resume execution, you press CTRL-D
98
99
100 == Console
101
102 You can interact with the domain model by starting the console through script/console.
103 Here you'll have all parts of the application configured, just like it is when the
104 application is running. You can inspect domain models, change values, and save to the
105 database. Starting the script without arguments will launch it in the development environment.
106 Passing an argument will specify a different environment, like <tt>console production</tt>.
107
108
109 == Description of contents
110
111 app
112   Holds all the code that's specific to this particular application.
113
114 app/controllers
115   Holds controllers that should be named like weblog_controller.rb for
116   automated URL mapping. All controllers should descend from
117   ActionController::Base.
118
119 app/models
120   Holds models that should be named like post.rb.
121   Most models will descend from ActiveRecord::Base.
122  
123 app/views
124   Holds the template files for the view that should be named like
125   weblog/index.rhtml for the WeblogController#index action. All views use eRuby
126   syntax. This directory can also be used to keep stylesheets, images, and so on
127   that can be symlinked to public.
128  
129 app/helpers
130   Holds view helpers that should be named like weblog_helper.rb.
131
132 config
133   Configuration files for the Rails environment, the routing map, the database, and other dependencies.
134
135 components
136   Self-contained mini-applications that can bundle together controllers, models, and views.
137
138 lib
139   Application specific libraries. Basically, any kind of custom code that doesn't
140   belong under controllers, models, or helpers. This directory is in the load path.
141    
142 public
143   The directory available for the web server. Contains subdirectories for images, stylesheets,
144   and javascripts. Also contains the dispatchers and the default HTML files.
145
146 script
147   Helper scripts for automation and generation.
148
149 test
150   Unit and functional tests along with fixtures.
151
152 vendor
153   External libraries that the application depends on. Also includes the plugins subdirectory.
154   This directory is in the load path.
Note: See TracBrowser for help on using the browser.

To edit pages or tickets please login with username/password: aaf/aaf