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

Benjamin Mako Hill || Want to submit a patch?