You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
4. Follow the guidelines to start developing your application
35
42
36
43
37
-
== Web Servers
44
+
Web Servers
45
+
-----------
38
46
39
47
By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
40
48
with a variety of other web servers.
@@ -48,51 +56,59 @@ Say other Ruby web servers like Thin and Ebb or regular web servers like Apache
48
56
Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
49
57
FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
50
58
51
-
== Apache .htaccess example for FCGI/CGI
59
+
Apache .htaccess example for FCGI/CGI
60
+
-------------------------------------
52
61
53
-
# General Apache options
54
-
AddHandler fastcgi-script .fcgi
55
-
AddHandler cgi-script .cgi
56
-
Options +FollowSymLinks +ExecCGI
62
+
**General Apache options**
63
+
```
64
+
AddHandler fastcgi-script .fcgi
65
+
AddHandler cgi-script .cgi
66
+
Options +FollowSymLinks +ExecCGI
67
+
```
57
68
58
-
# If you don't want Rails to look in certain directories,
59
-
# use the following rewrite rules so that Apache won't rewrite certain requests
60
-
#
61
-
# Example:
62
-
# RewriteCond %{REQUEST_URI} ^/notrails.*
63
-
# RewriteRule .* - [L]
69
+
If you don't want Rails to look in certain directories,
70
+
use the following rewrite rules so that Apache won't rewrite certain requests
71
+
72
+
Example:
73
+
```
74
+
RewriteCond %{REQUEST_URI} ^/notrails.*
75
+
RewriteRule .* - [L]
76
+
```
64
77
65
-
# Redirect all requests not available on the filesystem to Rails
66
-
# By default the cgi dispatcher is used which is very slow
67
-
#
68
-
# For better performance replace the dispatcher with the fastcgi one
69
-
#
70
-
# Example:
71
-
# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
72
-
RewriteEngine On
78
+
Redirect all requests not available on the filesystem to Rails
79
+
By default the cgi dispatcher is used which is very slow
80
+
81
+
For better performance replace the dispatcher with the fastcgi one
73
82
74
-
# If your Rails application is accessed via an Alias directive,
75
-
# then you MUST also set the RewriteBase in this htaccess file.
76
-
#
77
-
# Example:
78
-
# Alias /myrailsapp /path/to/myrailsapp/public
79
-
# RewriteBase /myrailsapp
83
+
Example:
84
+
```
85
+
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
86
+
RewriteEngine On
80
87
81
-
RewriteRule ^$ index.html [QSA]
82
-
RewriteRule ^([^.]+)$ $1.html [QSA]
83
-
RewriteCond %{REQUEST_FILENAME} !-f
84
-
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
88
+
If your Rails application is accessed via an Alias directive,
89
+
then you MUST also set the RewriteBase in this htaccess file.
85
90
86
-
# In case Rails experiences terminal errors
87
-
# Instead of displaying this message you can supply a file here which will be rendered instead
88
-
#
89
-
# Example:
90
-
# ErrorDocument 500 /500.html
91
+
Example:
92
+
```
93
+
Alias /myrailsapp /path/to/myrailsapp/public
94
+
RewriteBase /myrailsapp
95
+
96
+
RewriteRule ^$ index.html [QSA]
97
+
RewriteRule ^([^.]+)$ $1.html [QSA]
98
+
RewriteCond %{REQUEST_FILENAME} !-f
99
+
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
100
+
``
101
+
In case Rails experiences terminal errors, Instead of displaying this message you can supply a file here which will be rendered instead.
91
102
92
-
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
103
+
Example:
104
+
```
105
+
ErrorDocument 500 /500.html
93
106
107
+
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
108
+
```
94
109
95
-
== Debugging Rails
110
+
Debugging Rails
111
+
---------------
96
112
97
113
Sometimes your application goes wrong. Fortunately there are a lot of tools that
98
114
will help you debug it and get it back on the rails.
@@ -104,19 +120,19 @@ browser on requests from 127.0.0.1.
104
120
105
121
You can also log your own messages directly into the log file from your code using
106
122
the Ruby logger class from inside your controllers. Example:
107
-
123
+
```
108
124
class WeblogController < ActionController::Base
109
125
def destroy
110
126
@weblog = Weblog.find(params[:id])
111
127
@weblog.destroy
112
128
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
113
129
end
114
130
end
115
-
131
+
```
116
132
The result will be a message in your log file along the lines of:
117
-
133
+
```
118
134
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
119
-
135
+
```
120
136
More information on how to use the logger is at http://www.ruby-doc.org/core/
121
137
122
138
Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
@@ -128,41 +144,50 @@ These two online (and free) books will bring you up to speed on the Ruby languag
128
144
and also on programming in general.
129
145
130
146
131
-
== Debugger
147
+
Debugger
148
+
--------
132
149
133
150
Debugger support is available through the debugger command when you start your Mongrel or
134
151
Webrick server with --debugger. This means that you can break out of execution at any point
135
152
in the code, investigate and change the model, AND then resume execution!
136
153
You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
154
+
137
155
Example:
138
156
157
+
```
139
158
class WeblogController < ActionController::Base
140
159
def index
141
160
@posts = Post.find(:all)
142
161
debugger
143
162
end
144
163
end
164
+
```
145
165
146
166
So the controller will accept the action, run the first line, then present you
147
167
with a IRB prompt in the server window. Here you can do things like:
Finally, when you're ready to resume execution, you enter "cont"
163
187
164
188
165
-
== Console
189
+
Console
190
+
-------
166
191
167
192
You can interact with the domain model by starting the console through <tt>script/console</tt>.
168
193
Here you'll have all parts of the application configured, just like it is when the
@@ -172,72 +197,70 @@ Passing an argument will specify a different environment, like <tt>script/consol
172
197
173
198
To reload your controllers and models after launching the console run <tt>reload!</tt>
174
199
175
-
== dbconsole
200
+
**dbconsole**
176
201
177
202
You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
178
203
You would be connected to the database with the credentials defined in database.yml.
179
-
Starting the script without arguments will connect you to the development database. Passing an
180
-
argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
204
+
Starting the script without arguments will connect you to the development database. Passing an argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
205
+
181
206
Currently works for mysql, postgresql and sqlite.
182
207
183
-
== Description of Contents
208
+
Description of Contents
209
+
-----------------------
184
210
185
-
app
211
+
**app**
186
212
Holds all the code that's specific to this particular application.
187
213
188
-
app/controllers
214
+
**app/controllers**
189
215
Holds controllers that should be named like weblogs_controller.rb for
190
216
automated URL mapping. All controllers should descend from ApplicationController
191
217
which itself descends from ActionController::Base.
192
218
193
-
app/models
219
+
**app/models**
194
220
Holds models that should be named like post.rb.
195
221
Most models will descend from ActiveRecord::Base.
196
222
197
-
app/views
223
+
**app/views**
198
224
Holds the template files for the view that should be named like
199
225
weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
200
226
syntax.
201
227
202
-
app/views/layouts
228
+
**app/views/layouts**
203
229
Holds the template files for layouts to be used with views. This models the common
204
230
header/footer method of wrapping views. In your views, define a layout using the
205
-
<tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
231
+
<tt>layout :default</tt> and create a file named default.html.erb. Inside default.html
232
+
233
+
**.erb,**
206
234
call <% yield %> to render the view using this layout.
207
235
208
-
app/helpers
236
+
**app/helpers**
209
237
Holds view helpers that should be named like weblogs_helper.rb. These are generated
210
238
for you automatically when using script/generate for controllers. Helpers can be used to
211
239
wrap functionality for your views into methods.
212
240
213
-
config
241
+
**config**
214
242
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
215
243
216
-
db
244
+
**db**
217
245
Contains the database schema in schema.rb. db/migrate contains all
218
246
the sequence of Migrations for your schema.
219
247
220
-
doc
248
+
**doc**
221
249
This directory is where your application documentation will be stored when generated
222
250
using <tt>rake doc:app</tt>
223
251
224
-
lib
252
+
**lib**
225
253
Application specific libraries. Basically, any kind of custom code that doesn't
226
254
belong under controllers, models, or helpers. This directory is in the load path.
227
255
228
-
public
229
-
The directory available for the web server. Contains subdirectories for images, stylesheets,
230
-
and javascripts. Also contains the dispatchers and the default HTML files. This should be
231
-
set as the DOCUMENT_ROOT of your web server.
256
+
**public**
257
+
The directory available for the web server. Contains subdirectories for images, stylesheets, and javascripts. Also contains the dispatchers and the default HTML files. This should be set as the DOCUMENT_ROOT of your web server.
232
258
233
-
script
259
+
**script**
234
260
Helper scripts for automation and generation.
235
261
236
-
test
237
-
Unit and functional tests along with fixtures. When using the script/generate scripts, template
238
-
test files will be generated for you and placed in this directory.
262
+
**test**
263
+
Unit and functional tests along with fixtures. When using the script/generate scripts, template test files will be generated for you and placed in this directory.
239
264
240
-
vendor
241
-
External libraries that the application depends on. Also includes the plugins subdirectory.
242
-
If the app has frozen rails, those gems also go here, under vendor/rails/.
243
-
This directory is in the load path.
265
+
**vendor**
266
+
External libraries that the application depends on. Also includes the plugins subdirectory. If the app has frozen rails, those gems also go here, under vendor/rails/. This directory is in the load path.
0 commit comments