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. Start the web server: <tt>ruby script/server</tt> (run with --help for options)
 
  31 2. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
 
  32 3. Follow the guidelines to start developing your application
 
  37 Rails uses the built-in web server in Ruby called WEBrick by default, so you don't
 
  38 have to install or configure anything to play around. 
 
  40 If you have lighttpd installed, though, it'll be used instead when running script/server.
 
  41 It's considerably faster than WEBrick and suited for production use, but requires additional
 
  42 installation and currently only works well on OS X/Unix (Windows users are encouraged
 
  43 to start with WEBrick). We recommend version 1.4.11 and higher. You can download it from
 
  44 http://www.lighttpd.net.
 
  46 If you want something that's halfway between WEBrick and lighttpd, we heartily recommend
 
  47 Mongrel. It's a Ruby-based web server with a C-component (so it requires compilation) that
 
  48 also works very well with Windows. See more at http://mongrel.rubyforge.org/.
 
  50 But of course its also possible to run Rails with the premiere open source web server Apache.
 
  51 To get decent performance, though, you'll need to install FastCGI. For Apache 1.3, you want
 
  52 to use mod_fastcgi. For Apache 2.0+, you want to use mod_fcgid.
 
  54 See http://wiki.rubyonrails.com/rails/pages/FastCGI for more information on FastCGI.
 
  56 == Example for Apache conf
 
  60     DocumentRoot /path/application/public/
 
  61     ErrorLog /path/application/log/server.log
 
  63     <Directory /path/application/public/>
 
  64       Options ExecCGI FollowSymLinks
 
  71 NOTE: Be sure that CGIs can be executed in that directory as well. So ExecCGI
 
  72 should be on and ".cgi" should respond. All requests from 127.0.0.1 go
 
  73 through CGI, so no Apache restart is necessary for changes. All other requests
 
  74 go through FCGI (or mod_ruby), which requires a restart to show changes.
 
  79 Have "tail -f" commands running on both the server.log, production.log, and
 
  80 test.log files. Rails will automatically display debugging and runtime
 
  81 information to these files. Debugging info will also be shown in the browser
 
  82 on requests from 127.0.0.1.
 
  87 Breakpoint support is available through the script/breakpointer client. This
 
  88 means that you can break out of execution at any point in the code, investigate
 
  89 and change the model, AND then resume execution! Example:
 
  91   class WeblogController < ActionController::Base
 
  93       @posts = Post.find_all
 
  94       breakpoint "Breaking out from the list"
 
  98 So the controller will accept the action, run the first line, then present you
 
  99 with a IRB prompt in the breakpointer window. Here you can do things like:
 
 101 Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
 
 104   => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>, 
 
 105        #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
 
 106   >> @posts.first.title = "hello from a breakpoint"
 
 107   => "hello from a breakpoint"
 
 109 ...and even better is that you can examine how your runtime objects actually work:
 
 112   => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
 
 114   Display all 152 possibilities? (y or n)
 
 116 Finally, when you're ready to resume execution, you press CTRL-D
 
 121 You can interact with the domain model by starting the console through script/console. 
 
 122 Here you'll have all parts of the application configured, just like it is when the
 
 123 application is running. You can inspect domain models, change values, and save to the
 
 124 database. Starting the script without arguments will launch it in the development environment.
 
 125 Passing an argument will specify a different environment, like <tt>script/console production</tt>.
 
 128 == Description of contents
 
 131   Holds all the code that's specific to this particular application.
 
 134   Holds controllers that should be named like weblog_controller.rb for
 
 135   automated URL mapping. All controllers should descend from
 
 136   ActionController::Base.
 
 139   Holds models that should be named like post.rb.
 
 140   Most models will descend from ActiveRecord::Base.
 
 143   Holds the template files for the view that should be named like
 
 144   weblog/index.rhtml for the WeblogController#index action. All views use eRuby
 
 145   syntax. This directory can also be used to keep stylesheets, images, and so on
 
 146   that can be symlinked to public.
 
 149   Holds view helpers that should be named like weblog_helper.rb.
 
 152   Holds API classes for web services.
 
 155   Configuration files for the Rails environment, the routing map, the database, and other dependencies.
 
 158   Self-contained mini-applications that can bundle together controllers, models, and views.
 
 161   Contains the database schema in schema.rb.  db/migrate contains all
 
 162   the sequence of Migrations for your schema.
 
 165   Application specific libraries. Basically, any kind of custom code that doesn't
 
 166   belong under controllers, models, or helpers. This directory is in the load path.
 
 169   The directory available for the web server. Contains subdirectories for images, stylesheets,
 
 170   and javascripts. Also contains the dispatchers and the default HTML files.
 
 173   Helper scripts for automation and generation.
 
 176   Unit and functional tests along with fixtures.
 
 179   External libraries that the application depends on. Also includes the plugins subdirectory.
 
 180   This directory is in the load path.