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.
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.
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.
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
36 == Example for Apache conf
40 DocumentRoot /path/application/public/
41 ErrorLog /path/application/log/server.log
43 <Directory /path/application/public/>
44 Options ExecCGI FollowSymLinks
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.
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.
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:
71 class WeblogController < ActionController::Base
73 @posts = Post.find_all
74 breakpoint "Breaking out from the list"
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:
81 Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
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"
89 ...and even better is that you can examine how your runtime objects actually work:
92 => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
94 Display all 152 possibilities? (y or n)
96 Finally, when you're ready to resume execution, you press CTRL-D
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>.
108 == Description of contents
111 Holds all the code that's specific to this particular application.
114 Holds controllers that should be named like weblog_controller.rb for
115 automated URL mapping. All controllers should descend from
116 ActionController::Base.
119 Holds models that should be named like post.rb.
120 Most models will descend from ActiveRecord::Base.
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.
129 Holds view helpers that should be named like weblog_helper.rb.
132 Configuration files for the Rails environment, the routing map, the database, and other dependencies.
135 Self-contained mini-applications that can bundle together controllers, models, and views.
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.
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.
146 Helper scripts for automation and generation.
149 Unit and functional tests along with fixtures.
152 External libraries that the application depends on. Also includes the plugins subdirectory.
153 This directory is in the load path.