Skip to content

Commit 7db9c70

Browse files
committed
vanilla rails 3 beta 4 app
0 parents  commit 7db9c70

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+9079
-0
lines changed

Gemfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
source 'http://rubygems.org'
2+
3+
gem 'rails', '3.0.0.beta4'
4+
5+
# Bundle edge Rails instead:
6+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
7+
8+
gem 'sqlite3-ruby', :require => 'sqlite3'
9+
10+
# Use unicorn as the web server
11+
# gem 'unicorn'
12+
13+
# Deploy with Capistrano
14+
# gem 'capistrano'
15+
16+
# To use debugger
17+
# gem 'ruby-debug'
18+
19+
# Bundle the extra gems:
20+
# gem 'bj'
21+
# gem 'nokogiri', '1.4.1'
22+
# gem 'sqlite3-ruby', :require => 'sqlite3'
23+
# gem 'aws-s3', :require => 'aws/s3'
24+
25+
# Bundle gems for certain environments:
26+
# gem 'rspec', :group => :test
27+
# group :test do
28+
# gem 'webrat'
29+
# end

README

Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
== Welcome to Rails
2+
3+
Rails is a web-application framework that includes everything needed to create
4+
database-backed web applications according to the Model-View-Control pattern.
5+
6+
This pattern splits the view (also called the presentation) into "dumb"
7+
templates that are primarily responsible for inserting pre-built data in between
8+
HTML tags. The model contains the "smart" domain objects (such as Account,
9+
Product, Person, Post) that holds all the business logic and knows how to
10+
persist themselves to a database. The controller handles the incoming requests
11+
(such as Save New Account, Update Product, Show Post) by manipulating the model
12+
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. At the command prompt, create a new Rails application:
32+
<tt>rails myapp</tt> (where <tt>myapp</tt> is the application name)
33+
34+
2. Change directory to <tt>myapp</tt> and start the web server:
35+
<tt>cd myapp; rails server</tt> (run with --help for options)
36+
37+
3. Go to http://localhost:3000/ and you'll see:
38+
"Welcome aboard: You're riding the Rails!"
39+
40+
4. Follow the guidelines to start developing your application. You can find
41+
the following resources handy:
42+
43+
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44+
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45+
46+
47+
== Web Servers
48+
49+
By default, Rails will try to use Mongrel if it's installed when started with
50+
<tt>rails server</tt>, otherwise Rails will use WEBrick, the web server that
51+
ships with Ruby.
52+
53+
Mongrel is a Ruby-based web server with a C component (which requires
54+
compilation) that is suitable for development. If you have Ruby Gems installed,
55+
getting up and running with mongrel is as easy as:
56+
<tt>sudo gem install mongrel</tt>.
57+
58+
You can find more info at: http://mongrel.rubyforge.org
59+
60+
You can alternatively run Rails applications with other Ruby web servers, e.g.,
61+
{Thin}[http://code.macournoyer.com/thin/], {Ebb}[http://ebb.rubyforge.org/], and
62+
Apache with {mod_rails}[http://www.modrails.com/]. However, <tt>rails server</tt>
63+
doesn't search for or start them.
64+
65+
For production use, often a web/proxy server, e.g., {Apache}[http://apache.org],
66+
{Nginx}[http://nginx.net/], {LiteSpeed}[http://litespeedtech.com/],
67+
{Lighttpd}[http://www.lighttpd.net/], or {IIS}[http://www.iis.net/], is deployed
68+
as the front end server with the chosen Ruby web server running in the back end
69+
and receiving the proxied requests via one of several protocols (HTTP, CGI, FCGI).
70+
71+
72+
== Debugging Rails
73+
74+
Sometimes your application goes wrong. Fortunately there are a lot of tools that
75+
will help you debug it and get it back on the rails.
76+
77+
First area to check is the application log files. Have "tail -f" commands
78+
running on the server.log and development.log. Rails will automatically display
79+
debugging and runtime information to these files. Debugging info will also be
80+
shown in the browser on requests from 127.0.0.1.
81+
82+
You can also log your own messages directly into the log file from your code
83+
using the Ruby logger class from inside your controllers. Example:
84+
85+
class WeblogController < ActionController::Base
86+
def destroy
87+
@weblog = Weblog.find(params[:id])
88+
@weblog.destroy
89+
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
90+
end
91+
end
92+
93+
The result will be a message in your log file along the lines of:
94+
95+
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
96+
97+
More information on how to use the logger is at http://www.ruby-doc.org/core/
98+
99+
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
100+
several books available online as well:
101+
102+
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
103+
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
104+
105+
These two books will bring you up to speed on the Ruby language and also on
106+
programming in general.
107+
108+
109+
== Debugger
110+
111+
Debugger support is available through the debugger command when you start your
112+
Mongrel or WEBrick server with --debugger. This means that you can break out of
113+
execution at any point in the code, investigate and change the model, and then,
114+
resume execution! You need to install ruby-debug to run the server in debugging
115+
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
116+
117+
class WeblogController < ActionController::Base
118+
def index
119+
@posts = Post.find(:all)
120+
debugger
121+
end
122+
end
123+
124+
So the controller will accept the action, run the first line, then present you
125+
with a IRB prompt in the server window. Here you can do things like:
126+
127+
>> @posts.inspect
128+
=> "[#<Post:0x14a6be8
129+
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
130+
#<Post:0x14a6620
131+
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
132+
>> @posts.first.title = "hello from a debugger"
133+
=> "hello from a debugger"
134+
135+
...and even better, you can examine how your runtime objects actually work:
136+
137+
>> f = @posts.first
138+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
139+
>> f.
140+
Display all 152 possibilities? (y or n)
141+
142+
Finally, when you're ready to resume execution, you can enter "cont".
143+
144+
145+
== Console
146+
147+
The console is a Ruby shell, which allows you to interact with your
148+
application's domain model. Here you'll have all parts of the application
149+
configured, just like it is when the application is running. You can inspect
150+
domain models, change values, and save to the database. Starting the script
151+
without arguments will launch it in the development environment.
152+
153+
To start the console, run <tt>rails console</tt> from the application
154+
directory.
155+
156+
Options:
157+
158+
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
159+
made to the database.
160+
* Passing an environment name as an argument will load the corresponding
161+
environment. Example: <tt>rails console production</tt>.
162+
163+
To reload your controllers and models after launching the console run
164+
<tt>reload!</tt>
165+
166+
More information about irb can be found at:
167+
link:http://www.rubycentral.com/pickaxe/irb.html
168+
169+
170+
== dbconsole
171+
172+
You can go to the command line of your database directly through <tt>rails
173+
dbconsole</tt>. You would be connected to the database with the credentials
174+
defined in database.yml. Starting the script without arguments will connect you
175+
to the development database. Passing an argument will connect you to a different
176+
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
177+
PostgreSQL and SQLite 3.
178+
179+
== Description of Contents
180+
181+
The default directory structure of a generated Ruby on Rails application:
182+
183+
|-- app
184+
| |-- controllers
185+
| |-- helpers
186+
| |-- models
187+
| `-- views
188+
| `-- layouts
189+
|-- config
190+
| |-- environments
191+
| |-- initializers
192+
| `-- locales
193+
|-- db
194+
|-- doc
195+
|-- lib
196+
| `-- tasks
197+
|-- log
198+
|-- public
199+
| |-- images
200+
| |-- javascripts
201+
| `-- stylesheets
202+
|-- script
203+
| `-- performance
204+
|-- test
205+
| |-- fixtures
206+
| |-- functional
207+
| |-- integration
208+
| |-- performance
209+
| `-- unit
210+
|-- tmp
211+
| |-- cache
212+
| |-- pids
213+
| |-- sessions
214+
| `-- sockets
215+
`-- vendor
216+
`-- plugins
217+
218+
app
219+
Holds all the code that's specific to this particular application.
220+
221+
app/controllers
222+
Holds controllers that should be named like weblogs_controller.rb for
223+
automated URL mapping. All controllers should descend from
224+
ApplicationController which itself descends from ActionController::Base.
225+
226+
app/models
227+
Holds models that should be named like post.rb. Models descend from
228+
ActiveRecord::Base by default.
229+
230+
app/views
231+
Holds the template files for the view that should be named like
232+
weblogs/index.html.erb for the WeblogsController#index action. All views use
233+
eRuby syntax by default.
234+
235+
app/views/layouts
236+
Holds the template files for layouts to be used with views. This models the
237+
common header/footer method of wrapping views. In your views, define a layout
238+
using the <tt>layout :default</tt> and create a file named default.html.erb.
239+
Inside default.html.erb, call <% yield %> to render the view using this
240+
layout.
241+
242+
app/helpers
243+
Holds view helpers that should be named like weblogs_helper.rb. These are
244+
generated for you automatically when using generators for controllers.
245+
Helpers can be used to wrap functionality for your views into methods.
246+
247+
config
248+
Configuration files for the Rails environment, the routing map, the database,
249+
and other dependencies.
250+
251+
db
252+
Contains the database schema in schema.rb. db/migrate contains all the
253+
sequence of Migrations for your schema.
254+
255+
doc
256+
This directory is where your application documentation will be stored when
257+
generated using <tt>rake doc:app</tt>
258+
259+
lib
260+
Application specific libraries. Basically, any kind of custom code that
261+
doesn't belong under controllers, models, or helpers. This directory is in
262+
the load path.
263+
264+
public
265+
The directory available for the web server. Contains subdirectories for
266+
images, stylesheets, and javascripts. Also contains the dispatchers and the
267+
default HTML files. This should be set as the DOCUMENT_ROOT of your web
268+
server.
269+
270+
script
271+
Helper scripts for automation and generation.
272+
273+
test
274+
Unit and functional tests along with fixtures. When using the rails generate
275+
command, template test files will be generated for you and placed in this
276+
directory.
277+
278+
vendor
279+
External libraries that the application depends on. Also includes the plugins
280+
subdirectory. If the app has frozen rails, those gems also go here, under
281+
vendor/rails/. This directory is in the load path.

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
4+
require File.expand_path('../config/application', __FILE__)
5+
require 'rake'
6+
7+
Rails::Application.load_tasks
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class ApplicationController < ActionController::Base
2+
protect_from_forgery
3+
layout 'application'
4+
end

app/helpers/application_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module ApplicationHelper
2+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>AsyncRails3</title>
5+
<%= stylesheet_link_tag :all %>
6+
<%= javascript_include_tag :defaults %>
7+
<%= csrf_meta_tag %>
8+
</head>
9+
<body>
10+
11+
<%= yield %>
12+
13+
</body>
14+
</html>

config.ru

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file is used by Rack-based servers to start the application.
2+
3+
require ::File.expand_path('../config/environment', __FILE__)
4+
run AsyncRails3::Application

config/application.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require File.expand_path('../boot', __FILE__)
2+
3+
require 'rails/all'
4+
5+
# If you have a Gemfile, require the gems listed there, including any gems
6+
# you've limited to :test, :development, or :production.
7+
Bundler.require(:default, Rails.env) if defined?(Bundler)
8+
9+
module AsyncRails3
10+
class Application < Rails::Application
11+
# Settings in config/environments/* take precedence over those specified here.
12+
# Application configuration should go into files in config/initializers
13+
# -- all .rb files in that directory are automatically loaded.
14+
15+
# Add additional load paths for your own custom dirs
16+
# config.load_paths += %W( #{config.root}/extras )
17+
18+
# Only load the plugins named here, in the order given (default is alphabetical).
19+
# :all can be used as a placeholder for all plugins not explicitly named
20+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
21+
22+
# Activate observers that should always be running
23+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
24+
25+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
26+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
27+
# config.time_zone = 'Central Time (US & Canada)'
28+
29+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
30+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
31+
# config.i18n.default_locale = :de
32+
33+
# Configure generators values. Many other options are available, be sure to check the documentation.
34+
# config.generators do |g|
35+
# g.orm :active_record
36+
# g.template_engine :erb
37+
# g.test_framework :test_unit, :fixture => true
38+
# end
39+
40+
# Configure the default encoding used in templates for Ruby 1.9.
41+
config.encoding = "utf-8"
42+
43+
# Configure sensitive parameters which will be filtered from the log file.
44+
config.filter_parameters += [:password]
45+
end
46+
end

0 commit comments

Comments
 (0)