Commit 61e76a818d8e072b48ebf093d9e72699a1e6ecfb

initial commit

Commit diff

README

 
1== Welcome to Rails
2
3Rails is a web-application and persistence framework that includes everything
4needed to create database-backed web-applications according to the
5Model-View-Control pattern of separation. This pattern splits the view (also
6called the presentation) into "dumb" templates that are primarily responsible
7for 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
9the business logic and knows how to persist themselves to a database. The
10controller handles the incoming requests (such as Save New Account, Update
11Product, Show Post) by manipulating the model and directing data to the view.
12
13In Rails, the model is handled by what's called an object-relational mapping
14layer entitled Active Record. This layer allows you to present the data from
15database rows as objects and embellish these data objects with business logic
16methods. You can read more about Active Record in
17link:files/vendor/rails/activerecord/README.html.
18
19The controller and view are handled by the Action Pack, which handles both
20layers by its two parts: Action View and Action Controller. These two layers
21are bundled in a single package due to their heavy interdependence. This is
22unlike the relationship between the Active Record and Action Pack that is much
23more separate. Each of these packages can be used independently outside of
24Rails. You can read more about Action Pack in
25link:files/vendor/rails/actionpack/README.html.
26
27
28== Getting started
29
301. At the command prompt, start a new rails application using the rails command
31 and your application name. Ex: rails myapp
32 (If you've downloaded rails in a complete tgz or zip, this step is already done)
332. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
343. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
354. Follow the guidelines to start developing your application
36
37
38== Web Servers
39
40By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
41Rails will use the WEBrick, the webserver that ships with Ruby. When you run script/server,
42Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
43that you can always get up and running quickly.
44
45Mongrel is a Ruby-based webserver with a C-component (which requires compilation) that is
46suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
47getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
48More info at: http://mongrel.rubyforge.org
49
50If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
51Mongrel and WEBrick and also suited for production use, but requires additional
52installation and currently only works well on OS X/Unix (Windows users are encouraged
53to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
54http://www.lighttpd.net.
55
56And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
57web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
58for production.
59
60But of course its also possible to run Rails on any platform that supports FCGI.
61Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
62please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
63
64
65== Debugging Rails
66
67Have "tail -f" commands running on the server.log and development.log. Rails will
68automatically display debugging and runtime information to these files. Debugging
69info will also be shown in the browser on requests from 127.0.0.1.
70
71
72== Breakpoints
73
74Breakpoint support is available through the script/breakpointer client. This
75means that you can break out of execution at any point in the code, investigate
76and change the model, AND then resume execution! Example:
77
78 class WeblogController < ActionController::Base
79 def index
80 @posts = Post.find(:all)
81 breakpoint "Breaking out from the list"
82 end
83 end
84
85So the controller will accept the action, run the first line, then present you
86with a IRB prompt in the breakpointer window. Here you can do things like:
87
88Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
89
90 >> @posts.inspect
91 => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
92 #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
93 >> @posts.first.title = "hello from a breakpoint"
94 => "hello from a breakpoint"
95
96...and even better is that you can examine how your runtime objects actually work:
97
98 >> f = @posts.first
99 => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
100 >> f.
101 Display all 152 possibilities? (y or n)
102
103Finally, when you're ready to resume execution, you press CTRL-D
104
105
106== Console
107
108You can interact with the domain model by starting the console through <tt>script/console</tt>.
109Here you'll have all parts of the application configured, just like it is when the
110application is running. You can inspect domain models, change values, and save to the
111database. Starting the script without arguments will launch it in the development environment.
112Passing an argument will specify a different environment, like <tt>script/console production</tt>.
113
114To reload your controllers and models after launching the console run <tt>reload!</tt>
115
116To reload your controllers and models after launching the console run <tt>reload!</tt>
117
118
119
120== Description of contents
121
122app
123 Holds all the code that's specific to this particular application.
124
125app/controllers
126 Holds controllers that should be named like weblogs_controller.rb for
127 automated URL mapping. All controllers should descend from ApplicationController
128 which itself descends from ActionController::Base.
129
130app/models
131 Holds models that should be named like post.rb.
132 Most models will descend from ActiveRecord::Base.
133
134app/views
135 Holds the template files for the view that should be named like
136 weblogs/index.rhtml for the WeblogsController#index action. All views use eRuby
137 syntax.
138
139app/views/layouts
140 Holds the template files for layouts to be used with views. This models the common
141 header/footer method of wrapping views. In your views, define a layout using the
142 <tt>layout :default</tt> and create a file named default.rhtml. Inside default.rhtml,
143 call <% yield %> to render the view using this layout.
144
145app/helpers
146 Holds view helpers that should be named like weblogs_helper.rb. These are generated
147 for you automatically when using script/generate for controllers. Helpers can be used to
148 wrap functionality for your views into methods.
149
150config
151 Configuration files for the Rails environment, the routing map, the database, and other dependencies.
152
153components
154 Self-contained mini-applications that can bundle together controllers, models, and views.
155
156db
157 Contains the database schema in schema.rb. db/migrate contains all
158 the sequence of Migrations for your schema.
159
160doc
161 This directory is where your application documentation will be stored when generated
162 using <tt>rake doc:app</tt>
163
164lib
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.
167
168public
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. This should be
171 set as the DOCUMENT_ROOT of your web server.
172
173script
174 Helper scripts for automation and generation.
175
176test
177 Unit and functional tests along with fixtures. When using the script/generate scripts, template
178 test files will be generated for you and placed in this directory.
179
180vendor
181 External libraries that the application depends on. Also includes the plugins subdirectory.
182 This directory is in the load path.
toggle raw diff

Rakefile

 
1# Add your own tasks in files placed in lib/tasks ending in .rake,
2# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
4require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
6require 'rake'
7require 'rake/testtask'
8require 'rake/rdoctask'
9
10require 'tasks/rails'
toggle raw diff

app/controllers/application.rb

 
1# Filters added to this controller apply to all controllers in the application.
2# Likewise, all the methods added will be available for all controllers.
3
4class ApplicationController < ActionController::Base
5 # Pick a unique cookie name to distinguish our session data from others'
6 session :session_key => '_ks1_session_id'
7end
toggle raw diff

app/helpers/application_helper.rb

 
1# Methods added to this helper will be available to all templates in the application.
2module ApplicationHelper
3end
toggle raw diff

components/.gitignore

config/.gitignore

 
1database.yml
toggle raw diff

config/boot.rb

 
1# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb
2
3unless defined?(RAILS_ROOT)
4 root_path = File.join(File.dirname(__FILE__), '..')
5
6 unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
7 require 'pathname'
8 root_path = Pathname.new(root_path).cleanpath(true).to_s
9 end
10
11 RAILS_ROOT = root_path
12end
13
14unless defined?(Rails::Initializer)
15 if File.directory?("#{RAILS_ROOT}/vendor/rails")
16 require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
17 else
18 require 'rubygems'
19
20 environment_without_comments = IO.readlines(File.dirname(__FILE__) + '/environment.rb').reject { |l| l =~ /^#/ }.join
21 environment_without_comments =~ /[^#]RAILS_GEM_VERSION = '([\d.]+)'/
22 rails_gem_version = $1
23
24 if version = defined?(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION : rails_gem_version
25 # Asking for 1.1.6 will give you 1.1.6.5206, if available -- makes it easier to use beta gems
26 rails_gem = Gem.cache.search('rails', "~>#{version}.0").sort_by { |g| g.version.version }.last
27
28 if rails_gem
29 gem "rails", "=#{rails_gem.version.version}"
30 require rails_gem.full_gem_path + '/lib/initializer'
31 else
32 STDERR.puts %(Cannot find gem for Rails ~>#{version}.0:
33 Install the missing gem with 'gem install -v=#{version} rails', or
34 change environment.rb to define RAILS_GEM_VERSION with your desired version.
35 )
36 exit 1
37 end
38 else
39 gem "rails"
40 require 'initializer'
41 end
42 end
43
44 Rails::Initializer.run(:set_load_path)
45end
toggle raw diff

config/environment.rb

 
1# Be sure to restart your web server when you modify this file.
2
3# Uncomment below to force Rails into production mode when
4# you don't control web/app server and can't set it the proper way
5# ENV['RAILS_ENV'] ||= 'production'
6
7# Specifies gem version of Rails to use when vendor/rails is not present
8RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION
9
10# Bootstrap the Rails environment, frameworks, and default configuration
11require File.join(File.dirname(__FILE__), 'boot')
12
13Rails::Initializer.run do |config|
14 # Settings in config/environments/* take precedence over those specified here
15
16 # Skip frameworks you're not going to use (only works if using vendor/rails)
17 # config.frameworks -= [ :action_web_service, :action_mailer ]
18
19 # Only load the plugins named here, by default all plugins in vendor/plugins are loaded
20 # config.plugins = %W( exception_notification ssl_requirement )
21
22 # Add additional load paths for your own custom dirs
23 # config.load_paths += %W( #{RAILS_ROOT}/extras )
24
25 # Force all environments to use the same logger level
26 # (by default production uses :info, the others :debug)
27 # config.log_level = :debug
28
29 # Use the database for sessions instead of the file system
30 # (create the session table with 'rake db:sessions:create')
31 # config.action_controller.session_store = :active_record_store
32
33 # Use SQL instead of Active Record's schema dumper when creating the test database.
34 # This is necessary if your schema can't be completely dumped by the schema dumper,
35 # like if you have constraints or database-specific column types
36 # config.active_record.schema_format = :sql
37
38 # Activate observers that should always be running
39 # config.active_record.observers = :cacher, :garbage_collector
40
41 # Make Active Record use UTC-base instead of local time
42 # config.active_record.default_timezone = :utc
43
44 # See Rails::Configuration for more options
45end
46
47# Add new inflection rules using the following format
48# (all these examples are active by default):
49# Inflector.inflections do |inflect|
50# inflect.plural /^(ox)$/i, '\1en'
51# inflect.singular /^(ox)en/i, '\1'
52# inflect.irregular 'person', 'people'
53# inflect.uncountable %w( fish sheep )
54# end
55
56# Add new mime types for use in respond_to blocks:
57# Mime::Type.register "text/richtext", :rtf
58# Mime::Type.register "application/x-mobile", :mobile
59
60# Include your application configuration below
toggle raw diff

config/environments/development.rb

 
1# Settings specified here will take precedence over those in config/environment.rb
2
3# In the development environment your application's code is reloaded on
4# every request. This slows down response time but is perfect for development
5# since you don't have to restart the webserver when you make code changes.
6config.cache_classes = false
7
8# Log error messages when you accidentally call methods on nil.
9config.whiny_nils = true
10
11# Enable the breakpoint server that script/breakpointer connects to
12config.breakpoint_server = true
13
14# Show full error reports and disable caching
15config.action_controller.consider_all_requests_local = true
16config.action_controller.perform_caching = false
17config.action_view.cache_template_extensions = false
18config.action_view.debug_rjs = true
19
20# Don't care if the mailer can't send
21config.action_mailer.raise_delivery_errors = false
toggle raw diff

config/environments/production.rb

 
1# Settings specified here will take precedence over those in config/environment.rb
2
3# The production environment is meant for finished, "live" apps.
4# Code is not reloaded between requests
5config.cache_classes = true
6
7# Use a different logger for distributed setups
8# config.logger = SyslogLogger.new
9
10# Full error reports are disabled and caching is turned on
11config.action_controller.consider_all_requests_local = false
12config.action_controller.perform_caching = true
13
14# Enable serving of images, stylesheets, and javascripts from an asset server
15# config.action_controller.asset_host = "http://assets.example.com"
16
17# Disable delivery errors, bad email addresses will be ignored
18# config.action_mailer.raise_delivery_errors = false
toggle raw diff

config/environments/test.rb

 
1# Settings specified here will take precedence over those in config/environment.rb
2
3# The test environment is used exclusively to run your application's
4# test suite. You never need to work with it otherwise. Remember that
5# your test database is "scratch space" for the test suite and is wiped
6# and recreated between test runs. Don't rely on the data there!
7config.cache_classes = true
8
9# Log error messages when you accidentally call methods on nil.
10config.whiny_nils = true
11
12# Show full error reports and disable caching
13config.action_controller.consider_all_requests_local = true
14config.action_controller.perform_caching = false
15
16# Tell ActionMailer not to deliver emails to the real world.
17# The :test delivery method accumulates sent emails in the
18# ActionMailer::Base.deliveries array.
19config.action_mailer.delivery_method = :test
toggle raw diff

config/routes.rb

 
1ActionController::Routing::Routes.draw do |map|
2 # The priority is based upon order of creation: first created -> highest priority.
3
4 # Sample of regular route:
5 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
6 # Keep in mind you can assign values other than :controller and :action
7
8 # Sample of named route:
9 # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
10 # This route can be invoked with purchase_url(:id => product.id)
11
12 # You can have the root of your site routed by hooking up ''
13 # -- just remember to delete public/index.html.
14 # map.connect '', :controller => "welcome"
15
16 # Allow downloading Web Service WSDL as a file with an extension
17 # instead of a file named 'wsdl'
18 map.connect ':controller/service.wsdl', :action => 'wsdl'
19
20 # Install the default route as the lowest priority.
21 map.connect ':controller/:action/:id.:format'
22 map.connect ':controller/:action/:id'
23end
toggle raw diff

db/.gitignore

doc/README_FOR_APP

 
1Use this README file to introduce your application and point to useful places in the API for learning more.
2Run "rake appdoc" to generate API documentation for your models and controllers.
toggle raw diff

lib/tasks/.gitignore

log/.gitignore

 
1*.log
toggle raw diff

public/.htaccess

 
1# General Apache options
2AddHandler fastcgi-script .fcgi
3AddHandler cgi-script .cgi
4Options +FollowSymLinks +ExecCGI
5
6# If you don't want Rails to look in certain directories,
7# use the following rewrite rules so that Apache won't rewrite certain requests
8#
9# Example:
10# RewriteCond %{REQUEST_URI} ^/notrails.*
11# RewriteRule .* - [L]
12
13# Redirect all requests not available on the filesystem to Rails
14# By default the cgi dispatcher is used which is very slow
15#
16# For better performance replace the dispatcher with the fastcgi one
17#
18# Example:
19# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
20RewriteEngine On
21
22# If your Rails application is accessed via an Alias directive,
23# then you MUST also set the RewriteBase in this htaccess file.
24#
25# Example:
26# Alias /myrailsapp /path/to/myrailsapp/public
27# RewriteBase /myrailsapp
28
29RewriteRule ^$ index.html [QSA]
30RewriteRule ^([^.]+)$ $1.html [QSA]
31RewriteCond %{REQUEST_FILENAME} !-f
32RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
33
34# In case Rails experiences terminal errors
35# Instead of displaying this message you can supply a file here which will be rendered instead
36#
37# Example:
38# ErrorDocument 500 /500.html
39
40ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
toggle raw diff

public/404.html

 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
4<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
6<head>
7 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8 <title>The page you were looking for doesn't exist (404)</title>
9 <style type="text/css">
10 body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11 div.dialog {
12 width: 25em;
13 padding: 0 4em;
14 margin: 4em auto 0 auto;
15 border: 1px solid #ccc;
16 border-right-color: #999;
17 border-bottom-color: #999;
18 }
19 h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20 </style>
21</head>
22
23<body>
24 <!-- This file lives in public/404.html -->
25 <div class="dialog">
26 <h1>The page you were looking for doesn't exist.</h1>
27 <p>You may have mistyped the address or the page may have moved.</p>
28 </div>
29</body>
30</html>
toggle raw diff

public/500.html

 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
4<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
6<head>
7 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8 <title>We're sorry, but something went wrong</title>
9 <style type="text/css">
10 body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11 div.dialog {
12 width: 25em;
13 padding: 0 4em;
14 margin: 4em auto 0 auto;
15 border: 1px solid #ccc;
16 border-right-color: #999;
17 border-bottom-color: #999;
18 }
19 h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20 </style>
21</head>
22
23<body>
24 <!-- This file lives in public/500.html -->
25 <div class="dialog">
26 <h1>We're sorry, but something went wrong.</h1>
27 <p>We've been notified about this issue and we'll take a look at it shortly.</p>
28 </div>
29</body>
30</html>
toggle raw diff

public/dispatch.cgi

 
1#!/opt/local/bin/ruby
2
3require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
4
5# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
6# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired
7require "dispatcher"