railties 3.0.20 → 3.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +36 -49
- data/README.rdoc +2 -1
- data/guides/assets/stylesheets/fixes.css +16 -0
- data/guides/rails_guides.rb +2 -2
- data/guides/rails_guides/generator.rb +8 -3
- data/guides/rails_guides/textile_extensions.rb +4 -2
- data/guides/source/2_2_release_notes.textile +3 -3
- data/guides/source/2_3_release_notes.textile +2 -2
- data/guides/source/3_0_release_notes.textile +14 -14
- data/guides/source/action_controller_overview.textile +54 -79
- data/guides/source/action_mailer_basics.textile +39 -9
- data/guides/source/action_view_overview.textile +257 -211
- data/guides/source/active_record_basics.textile +1 -1
- data/guides/source/active_record_querying.textile +217 -27
- data/guides/source/active_record_validations_callbacks.textile +94 -25
- data/guides/source/active_support_core_extensions.textile +109 -77
- data/guides/source/ajax_on_rails.textile +15 -150
- data/guides/source/api_documentation_guidelines.textile +12 -12
- data/guides/source/association_basics.textile +74 -60
- data/guides/source/caching_with_rails.textile +59 -60
- data/guides/source/command_line.textile +46 -47
- data/guides/source/configuring.textile +55 -37
- data/guides/source/contribute.textile +7 -7
- data/guides/source/contributing_to_ruby_on_rails.textile +14 -23
- data/guides/source/credits.html.erb +3 -3
- data/guides/source/debugging_rails_applications.textile +59 -46
- data/guides/source/form_helpers.textile +76 -31
- data/guides/source/generators.textile +39 -40
- data/guides/source/getting_started.textile +73 -94
- data/guides/source/i18n.textile +64 -58
- data/guides/source/index.html.erb +3 -3
- data/guides/source/initialization.textile +634 -3284
- data/guides/source/layout.html.erb +6 -7
- data/guides/source/layouts_and_rendering.textile +59 -60
- data/guides/source/migrations.textile +63 -59
- data/guides/source/nested_model_forms.textile +2 -2
- data/guides/source/performance_testing.textile +16 -16
- data/guides/source/plugins.textile +236 -1280
- data/guides/source/rails_application_templates.textile +37 -29
- data/guides/source/rails_on_rack.textile +4 -9
- data/guides/source/routing.textile +96 -75
- data/guides/source/ruby_on_rails_guides_guidelines.textile +19 -12
- data/guides/source/security.textile +57 -30
- data/guides/source/testing.textile +26 -24
- data/guides/w3c_validator.rb +2 -2
- data/lib/rails.rb +1 -7
- data/lib/rails/application.rb +46 -76
- data/lib/rails/application/bootstrap.rb +6 -11
- data/lib/rails/application/configuration.rb +43 -40
- data/lib/rails/application/finisher.rb +16 -4
- data/lib/rails/application/railties.rb +6 -24
- data/lib/rails/application/routes_reloader.rb +45 -0
- data/lib/rails/backtrace_cleaner.rb +1 -1
- data/lib/rails/cli.rb +7 -5
- data/lib/rails/commands.rb +27 -2
- data/lib/rails/commands/application.rb +14 -1
- data/lib/rails/commands/benchmarker.rb +3 -1
- data/lib/rails/commands/dbconsole.rb +2 -2
- data/lib/rails/commands/destroy.rb +3 -1
- data/lib/rails/commands/generate.rb +3 -1
- data/lib/rails/commands/plugin.rb +2 -7
- data/lib/rails/commands/plugin_new.rb +10 -0
- data/lib/rails/commands/profiler.rb +3 -1
- data/lib/rails/commands/server.rb +4 -0
- data/lib/rails/configuration.rb +8 -81
- data/lib/rails/console/app.rb +2 -2
- data/lib/rails/engine.rb +460 -78
- data/lib/rails/engine/configuration.rb +46 -49
- data/lib/rails/engine/railties.rb +33 -0
- data/lib/rails/generators.rb +11 -5
- data/lib/rails/generators/actions.rb +2 -27
- data/lib/rails/generators/app_base.rb +216 -0
- data/lib/rails/generators/base.rb +3 -2
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb +1 -1
- data/lib/rails/generators/generated_attribute.rb +2 -1
- data/lib/rails/generators/migration.rb +6 -2
- data/lib/rails/generators/named_base.rb +79 -3
- data/lib/rails/generators/rails/app/app_generator.rb +44 -209
- data/lib/rails/generators/rails/app/templates/Gemfile +15 -31
- data/lib/rails/generators/rails/app/templates/README +2 -2
- data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
- data/lib/rails/generators/rails/app/templates/{public → app/assets}/images/rails.png +0 -0
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +8 -0
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +5 -0
- data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/application.rb +19 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +4 -4
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +11 -6
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -2
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +14 -11
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +5 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +12 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
- data/lib/rails/generators/rails/app/templates/db/{seeds.rb → seeds.rb.tt} +2 -2
- data/lib/rails/generators/rails/app/templates/public/index.html +10 -8
- data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/{test_helper.rb.tt → test_helper.rb} +0 -0
- data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
- data/lib/rails/generators/rails/assets/USAGE +20 -0
- data/lib/rails/generators/rails/assets/assets_generator.rb +39 -0
- data/lib/rails/generators/rails/assets/templates/javascript.js +2 -0
- data/lib/rails/generators/rails/assets/templates/javascript.js.coffee +3 -0
- data/lib/rails/generators/rails/assets/templates/stylesheet.css +4 -0
- data/lib/rails/generators/rails/assets/templates/stylesheet.css.scss +5 -0
- data/lib/rails/generators/rails/controller/controller_generator.rb +1 -1
- data/lib/rails/generators/rails/controller/templates/controller.rb +2 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +2 -2
- data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
- data/lib/rails/generators/rails/helper/templates/helper.rb +2 -0
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +7 -0
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -4
- data/lib/rails/generators/rails/plugin_new/USAGE +10 -0
- data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +303 -0
- data/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +9 -0
- data/lib/rails/generators/rails/plugin_new/templates/Gemfile +11 -0
- data/lib/rails/generators/rails/plugin_new/templates/MIT-LICENSE +20 -0
- data/lib/rails/generators/rails/plugin_new/templates/README.rdoc +3 -0
- data/lib/rails/generators/rails/plugin_new/templates/Rakefile +21 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/application_controller.rb.tt +4 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/application_helper.rb.tt +4 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/templates/config/routes.rb +6 -0
- data/lib/rails/generators/rails/plugin_new/templates/gitignore +6 -0
- data/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb +6 -0
- data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +7 -0
- data/lib/rails/generators/rails/plugin_new/templates/lib/tasks/%name%_tasks.rake +4 -0
- data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +16 -0
- data/lib/rails/generators/rails/plugin_new/templates/rails/boot.rb +10 -0
- data/lib/rails/generators/rails/plugin_new/templates/rails/routes.rb +4 -0
- data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +5 -0
- data/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb +7 -0
- data/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb +12 -0
- data/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb +10 -0
- data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +20 -1
- data/lib/rails/generators/rails/{stylesheets → scaffold}/templates/scaffold.css +0 -0
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss +58 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +21 -19
- data/lib/rails/generators/resource_helpers.rb +3 -3
- data/lib/rails/generators/test_case.rb +2 -20
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +5 -4
- data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +2 -0
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +3 -4
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +5 -4
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml +1 -1
- data/lib/rails/generators/test_unit/model/templates/unit_test.rb +5 -4
- data/lib/rails/generators/test_unit/observer/templates/unit_test.rb +5 -4
- data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +3 -4
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +7 -5
- data/lib/rails/info.rb +0 -1
- data/lib/rails/paths.rb +119 -65
- data/lib/rails/plugin.rb +18 -19
- data/lib/rails/rack/log_tailer.rb +1 -1
- data/lib/rails/railtie.rb +50 -47
- data/lib/rails/railtie/configurable.rb +20 -10
- data/lib/rails/railtie/configuration.rb +20 -19
- data/lib/rails/source_annotation_extractor.rb +5 -5
- data/lib/rails/tasks.rb +1 -0
- data/lib/rails/tasks/assets.rake +10 -0
- data/lib/rails/tasks/documentation.rake +2 -8
- data/lib/rails/tasks/engine.rake +69 -0
- data/lib/rails/tasks/framework.rake +4 -21
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/routes.rake +2 -1
- data/lib/rails/test_help.rb +17 -1
- data/lib/rails/test_unit/railtie.rb +1 -1
- data/lib/rails/test_unit/testing.rake +8 -3
- data/lib/rails/version.rb +3 -3
- metadata +128 -100
- checksums.yaml +0 -7
- data/lib/rails/application/configurable.rb +0 -19
- data/lib/rails/console/sandbox.rb +0 -6
- data/lib/rails/deprecation.rb +0 -41
- data/lib/rails/engine/configurable.rb +0 -25
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +0 -62
- data/lib/rails/generators/rails/app/templates/public/javascripts/application.js +0 -2
- data/lib/rails/generators/rails/app/templates/public/javascripts/controls.js +0 -965
- data/lib/rails/generators/rails/app/templates/public/javascripts/dragdrop.js +0 -974
- data/lib/rails/generators/rails/app/templates/public/javascripts/effects.js +0 -1123
- data/lib/rails/generators/rails/app/templates/public/javascripts/prototype.js +0 -6001
- data/lib/rails/generators/rails/app/templates/public/javascripts/rails.js +0 -202
- data/lib/rails/generators/rails/stylesheets/USAGE +0 -5
- data/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb +0 -9
- data/lib/rails/info_routes.rb +0 -3
@@ -42,9 +42,9 @@ h4. Rails General Configuration
|
|
42
42
|
* +config.after_initialize+ takes a block which will be ran _after_ Rails has finished initializing. Useful for configuring values set up by other initializers:
|
43
43
|
|
44
44
|
<ruby>
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
config.after_initialize do
|
46
|
+
ActionView::Base.sanitized_allowed_tags.delete 'div'
|
47
|
+
end
|
48
48
|
</ruby>
|
49
49
|
|
50
50
|
* +config.allow_concurrency+ should be set to +true+ to allow concurrent (threadsafe) action processing. Set to +false+ by default. You probably don't want to call this one directly, though, because a series of other adjustments need to be made for threadsafe mode to work properly. Can also be enabled with +threadsafe!+.
|
@@ -63,6 +63,8 @@ h4. Rails General Configuration
|
|
63
63
|
|
64
64
|
* +config.cache_classes+ controls whether or not application classes should be reloaded on each request. Defaults to _true_ in development, _false_ in test and production. Can also be enabled with +threadsafe!+.
|
65
65
|
|
66
|
+
* +config.action_view.cache_template_loading+ controls whether or not templates should be reloaded on each request. Defaults to whatever is set for config.cache_classes.
|
67
|
+
|
66
68
|
* +config.cache_store+ configures which cache store to use for Rails caching. Options include +:memory_store+, +:file_store+, +:mem_cache_store+ or the name of your own custom class. Defaults to +:file_store+.
|
67
69
|
|
68
70
|
* +config.colorize_logging+ specifies whether or not to use ANSI color codes when logging information. Defaults to _true_.
|
@@ -79,6 +81,8 @@ h4. Rails General Configuration
|
|
79
81
|
|
80
82
|
* +config.filter_parameters+ used for filtering out the parameters that you don't want shown in the logs, such as passwords or credit card numbers.
|
81
83
|
|
84
|
+
* +config.force_ssl+ forcing all requests to be under HTTPS protocol by using +Rack::SSL+ middleware. This will secure your application from a session hijack attempt.
|
85
|
+
|
82
86
|
* +config.helper_paths+ configures where Rails can find helpers for this application.
|
83
87
|
|
84
88
|
* +config.log_level+ defines the verbosity of the Rails logger. In production mode, this defaults to +:info+. In development mode, it defaults to +:debug+.
|
@@ -115,7 +119,7 @@ WARNING: Threadsafe operation is incompatible with the normal workings of develo
|
|
115
119
|
|
116
120
|
* +config.time_zone+ sets the default time zone for the application and enables time zone awareness for Active Record.
|
117
121
|
|
118
|
-
* +config.whiny_nils+ enables or
|
122
|
+
* +config.whiny_nils+ enables or disables warnings when any methods of nil are invoked. Defaults to _true_ in development and test environments.
|
119
123
|
|
120
124
|
h4. Configuring Generators
|
121
125
|
|
@@ -131,12 +135,12 @@ Rails 3 allows you to alter what generators are used with the +config.generators
|
|
131
135
|
The full set of methods that can be used in this block are as follows:
|
132
136
|
|
133
137
|
* +force_plural+ allows pluralized model names. Defaults to _false_.
|
134
|
-
* +helper+ defines whether or not to generate helpers. Defaults to _true_
|
138
|
+
* +helper+ defines whether or not to generate helpers. Defaults to _true_.
|
135
139
|
* +orm+ defines which orm to use. Defaults to _nil_, so will use Active Record by default.
|
136
|
-
* +integration_tool+ defines which integration tool to use. Defaults to _nil_
|
137
|
-
* +performance_tool+ defines which performance tool to use. Defaults to _nil_
|
140
|
+
* +integration_tool+ defines which integration tool to use. Defaults to _nil_.
|
141
|
+
* +performance_tool+ defines which performance tool to use. Defaults to _nil_.
|
138
142
|
* +resource_controller+ defines which generator to use for generating a controller when using +rails generate resource+. Defaults to +:controller+.
|
139
|
-
* +scaffold_controller+ different from +resource_controller+, defines which generator to use for generating a _scaffolded_ controller when using +rails generate scaffold+. Defaults to +:scaffold_controller
|
143
|
+
* +scaffold_controller+ different from +resource_controller+, defines which generator to use for generating a _scaffolded_ controller when using +rails generate scaffold+. Defaults to +:scaffold_controller+.
|
140
144
|
* +stylesheets+ turns on the hook for stylesheets in generators. Used in Rails for when the +scaffold+ generator is ran, but this hook can be used in other generates as well.
|
141
145
|
* +test_framework+ defines which test framework to use. Defaults to _nil_, so will use Test::Unit by default.
|
142
146
|
* +template_engine+ defines which template engine to use, such as ERB or Haml. Defaults to +:erb+.
|
@@ -145,6 +149,7 @@ h4. Configuring Middleware
|
|
145
149
|
|
146
150
|
Every Rails application comes with a standard set of middleware which it uses in this order in the development environment:
|
147
151
|
|
152
|
+
* +Rack::SSL+ Will force every request to be under HTTPS protocol. Will be available if +config.force_ssl+ is set to _true_.
|
148
153
|
* +ActionDispatch::Static+ is used to serve static assets. Disabled if +config.serve_static_assets+ is _true_.
|
149
154
|
* +Rack::Lock+ Will wrap the app in mutex so it can only be called by a single thread at a time. Only enabled if +config.action_controller.allow_concurrency+ is set to _false_, which it is by default.
|
150
155
|
* +ActiveSupport::Cache::Strategy::LocalCache+ Serves as a basic memory backed cache. This cache is not thread safe and is intended only for serving as a temporary memory cache for a single thread.
|
@@ -152,7 +157,7 @@ Every Rails application comes with a standard set of middleware which it uses in
|
|
152
157
|
* +Rails::Rack::Logger+ Will notify the logs that the request has began. After request is complete, flushes all the logs.
|
153
158
|
* +ActionDispatch::ShowExceptions+ rescues any exception returned by the application and renders nice exception pages if the request is local or if +config.consider_all_requests_local+ is set to _true_. If +config.action_dispatch.show_exceptions+ is set to _false_, exceptions will be raised regardless.
|
154
159
|
* +ActionDispatch::RemoteIp+ checks for IP spoofing attacks. Configurable with the +config.action_dispatch.ip_spoofing_check+ and +config.action_dispatch.trusted_proxies+ settings.
|
155
|
-
* +Rack::Sendfile+ The Sendfile middleware intercepts responses whose body is being served from a file and replaces it with a server specific X-Sendfile header. Configurable with +config.
|
160
|
+
* +Rack::Sendfile+ The Sendfile middleware intercepts responses whose body is being served from a file and replaces it with a server specific X-Sendfile header. Configurable with +config.action_dispatch.x_sendfile_header+
|
156
161
|
* +ActionDispatch::Callbacks+ Runs the prepare callbacks before serving the request.
|
157
162
|
* +ActiveRecord::ConnectionAdapters::ConnectionManagement+ cleans active connections after each request, unless the +rack.test+ key in the request environment is set to _true_.
|
158
163
|
* +ActiveRecord::QueryCache+ caches all +SELECT+ queries generated in a request. If an +INSERT+ or +UPDATE+ takes place then the cache is cleaned.
|
@@ -188,6 +193,12 @@ Middlewares can also be completely swapped out and replaced with others:
|
|
188
193
|
config.middleware.swap ActionDispatch::BestStandardsSupport, Magical::Unicorns
|
189
194
|
</ruby>
|
190
195
|
|
196
|
+
They can also be removed from the stack completely:
|
197
|
+
|
198
|
+
<ruby>
|
199
|
+
config.middleware.delete ActionDispatch::BestStandardsSupport
|
200
|
+
</ruby>
|
201
|
+
|
191
202
|
h4. Configuring i18n
|
192
203
|
|
193
204
|
* +config.i18n.default_locale+ sets the default locale of an application used for i18n. Defaults to +:en+.
|
@@ -210,7 +221,7 @@ h4. Configuring Active Record
|
|
210
221
|
|
211
222
|
* +config.active_record.pluralize_table_names+ specifies whether Rails will look for singular or plural table names in the database. If set to +true+ (the default), then the Customer class will use the +customers+ table. If set to +false+, then the Customers class will use the +customer+ table.
|
212
223
|
|
213
|
-
* +config.active_record.default_timezone+ determines whether to use +Time.local+ (if set to +:local+) or +Time.utc+ (if set to +:utc+) when pulling dates and times from the database. The default is +:local
|
224
|
+
* +config.active_record.default_timezone+ determines whether to use +Time.local+ (if set to +:local+) or +Time.utc+ (if set to +:utc+) when pulling dates and times from the database. The default is +:utc+ for Rails, although ActiveRecord defaults to +:local+ when used outside of Rails.
|
214
225
|
|
215
226
|
* +config.active_record.schema_format+ controls the format for dumping the database schema to a file. The options are +:ruby+ (the default) for a database-independent version that depends on migrations, or +:sql+ for a set of (potentially database-dependent) SQL statements.
|
216
227
|
|
@@ -218,6 +229,8 @@ h4. Configuring Active Record
|
|
218
229
|
|
219
230
|
* +config.active_record.lock_optimistically+ controls whether ActiveRecord will use optimistic locking. By default this is +true+.
|
220
231
|
|
232
|
+
* +config.active_record.whitelist_attributes+ will create an empty whitelist of attributes available for mass-assignment security for all models in your app.
|
233
|
+
|
221
234
|
The MySQL adapter adds one additional configuration option:
|
222
235
|
|
223
236
|
* +ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans+ controls whether ActiveRecord will consider all +tinyint(1)+ columns in a MySQL database to be booleans. By default this is +true+.
|
@@ -234,7 +247,7 @@ h4. Configuring Action Controller
|
|
234
247
|
|
235
248
|
* +config.action_controller.asset_path+ takes a block which configures where assets can be found. Shorter version of +config.action_controller.asset_path+.
|
236
249
|
|
237
|
-
* +config.action_controller.page_cache_directory+ should be the document root for the web server and is set using <tt>Base.page_cache_directory = "/document/root"</tt>. For Rails, this directory has already been set to Rails.public_path (which is usually set to <tt>Rails.root + "/public"</tt>). Changing this setting can be useful to avoid naming conflicts with files in <tt>public/</tt>, but doing so will likely require configuring your web server to look in the new location for cached files.
|
250
|
+
* +config.action_controller.page_cache_directory+ should be the document root for the web server and is set using <tt>Base.page_cache_directory = "/document/root"</tt>. For Rails, this directory has already been set to +Rails.public_path+ (which is usually set to <tt>Rails.root + "/public"</tt>). Changing this setting can be useful to avoid naming conflicts with files in <tt>public/</tt>, but doing so will likely require configuring your web server to look in the new location for cached files.
|
238
251
|
|
239
252
|
* +config.action_controller.page_cache_extension+ configures the extension used for cached pages saved to +page_cache_directory+. Defaults to +.html+
|
240
253
|
|
@@ -244,23 +257,15 @@ h4. Configuring Action Controller
|
|
244
257
|
|
245
258
|
* +config.action_controller.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Controller. Set to nil to disable logging.
|
246
259
|
|
247
|
-
* +config.action_controller.resource_action_separator+ gives the token to be used between resources and actions when building or interpreting RESTful URLs. By default, this is "/".
|
248
|
-
|
249
|
-
* +config.action_controller.resource_path_names+ is a hash of default names for several RESTful actions. By default, the new action is named +new+ and the edit action is named +edit+.
|
250
|
-
|
251
260
|
* +config.action_controller.request_forgery_protection_token+ sets the token parameter name for RequestForgery. Calling +protect_from_forgery+ sets it to +:authenticity_token+ by default.
|
252
261
|
|
253
|
-
* +config.action_controller.optimise_named_routes+ turns on some optimizations in generating the routing table. It is set to +true+ by default.
|
254
|
-
|
255
|
-
* +config.action_controller.use_accept_header+ sets the rules for determining the response format. If this is set to +true+ (the default) then +respond_to+ and +Request#format+ will take the Accept header into account. If it is set to false then the request format will be determined solely by examining +params[:format]+. If there is no +format+ parameter, then the response format will be either HTML or Javascript depending on whether the request is an AJAX request.
|
256
|
-
|
257
262
|
* +config.action_controller.allow_forgery_protection+ enables or disables CSRF protection. By default this is +false+ in test mode and +true+ in all other modes.
|
258
263
|
|
259
264
|
* +config.action_controller.relative_url_root+ can be used to tell Rails that you are deploying to a subdirectory. The default is +ENV['RAILS_RELATIVE_URL_ROOT']+.
|
260
265
|
|
261
266
|
The caching code adds two additional settings:
|
262
267
|
|
263
|
-
* +ActionController::Base.page_cache_directory+ sets the directory where Rails will create cached pages for your web server. The default is +Rails.public_path+ (which is usually set to
|
268
|
+
* +ActionController::Base.page_cache_directory+ sets the directory where Rails will create cached pages for your web server. The default is +Rails.public_path+ (which is usually set to <tt>Rails.root + "/public"</tt>).
|
264
269
|
|
265
270
|
* +ActionController::Base.page_cache_extension+ sets the extension to be used when generating pages for the cache (this is ignored if the incoming request already has an extension). The default is +.html+.
|
266
271
|
|
@@ -278,18 +283,16 @@ h4. Configuring Action Dispatch
|
|
278
283
|
|
279
284
|
* +config.action_dispatch.tld_length+ sets the TLD (top-level domain) length for the application. Defaults to +1+.
|
280
285
|
|
281
|
-
* +ActionDispatch::Callbacks.before+ takes a block of code to run before the request.
|
286
|
+
* +ActionDispatch::Callbacks.before+ takes a block of code to run before the request.
|
282
287
|
|
283
288
|
* +ActionDispatch::Callbacks.to_prepare+ takes a block to run after +ActionDispatch::Callbacks.before+, but before the request. Runs for every request in +development+ mode, but only once for +production+ or environments with +cache_classes+ set to +true+.
|
284
289
|
|
285
|
-
* +ActionDispatch::Callbacks.after+ takes a block of code to run after the request.
|
290
|
+
* +ActionDispatch::Callbacks.after+ takes a block of code to run after the request.
|
286
291
|
|
287
292
|
h4. Configuring Action View
|
288
293
|
|
289
294
|
There are only a few configuration options for Action View, starting with four on +ActionView::Base+:
|
290
295
|
|
291
|
-
* +config.action_view.debug_rjs+ specifies whether RJS responses should be wrapped in a try/catch block that alert()s the caught exception (and then re-raises it). The default is +false+.
|
292
|
-
|
293
296
|
* +config.action_view.field_error_proc+ provides an HTML generator for displaying errors that come from Active Record. The default is <tt>Proc.new{ |html_tag, instance| %Q(%<div class="field_with_errors">#{html_tag}</div>).html_safe }</tt>
|
294
297
|
|
295
298
|
* +config.action_view.default_form_builder+ tells Rails which form builder to use by default. The default is +ActionView::Helpers::FormBuilder+.
|
@@ -298,7 +301,7 @@ There are only a few configuration options for Action View, starting with four o
|
|
298
301
|
|
299
302
|
* +config.action_view.erb_trim_mode+ gives the trim mode to be used by ERB. It defaults to +'-'+. See the "ERB documentation":http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/ for more information.
|
300
303
|
|
301
|
-
* +config.action_view.javascript_expansions+ a hash
|
304
|
+
* +config.action_view.javascript_expansions+ is a hash containing expansions that can be used for the JavaScript include tag. By default, this is defined as:
|
302
305
|
|
303
306
|
<ruby>
|
304
307
|
config.action_view.javascript_expansions = { :defaults => ['prototype', 'effects', 'dragdrop', 'controls', 'rails'] }
|
@@ -310,7 +313,7 @@ However, you may add to this by defining others:
|
|
310
313
|
config.action_view.javascript_expansions[:jquery] = ["jquery", "jquery-ui"]
|
311
314
|
</ruby>
|
312
315
|
|
313
|
-
|
316
|
+
And can reference in the view with the following code:
|
314
317
|
|
315
318
|
<ruby>
|
316
319
|
<%= javascript_include_tag :jquery %>
|
@@ -376,20 +379,36 @@ There are a few configuration options available in Active Support:
|
|
376
379
|
|
377
380
|
* +ActiveSupport::Cache::Store.logger+ specifies the logger to use within cache store operations.
|
378
381
|
|
382
|
+
* +ActiveSupport::Deprecation.behavior+ alternative setter to +config.active_support.deprecation+ which configures the behavior of deprecation warnings for Rails.
|
383
|
+
|
384
|
+
* +ActiveSupport::Deprecation.silence+ takes a block in which all deprecation warnings are silenced.
|
385
|
+
|
386
|
+
* +ActiveSupport::Deprecation.silenced+ sets whether or not to display deprecation warnings.
|
387
|
+
|
379
388
|
* +ActiveSupport::Logger.silencer+ is set to +false+ to disable the ability to silence logging in a block. The default is +true+.
|
380
389
|
|
390
|
+
|
381
391
|
h3. Rails Environment Settings
|
382
392
|
|
383
393
|
Some parts of Rails can also be configured externally by supplying environment variables. The following environment variables are recognized by various parts of Rails:
|
384
394
|
|
385
|
-
* +ENV[
|
395
|
+
* +ENV["RAILS_ENV"]+ defines the Rails environment (production, development, test, and so on) that Rails will run under.
|
386
396
|
|
387
|
-
* +ENV[
|
397
|
+
* +ENV["RAILS_RELATIVE_URL_ROOT"]+ is used by the routing code to recognize URLs when you deploy your application to a subdirectory.
|
388
398
|
|
389
399
|
* +ENV["RAILS_ASSET_ID"]+ will override the default cache-busting timestamps that Rails generates for downloadable assets.
|
390
400
|
|
391
401
|
* +ENV["RAILS_CACHE_ID"]+ and +ENV["RAILS_APP_VERSION"]+ are used to generate expanded cache keys in Rails' caching code. This allows you to have multiple separate caches from the same application.
|
392
402
|
|
403
|
+
|
404
|
+
h3. Using Initializer Files
|
405
|
+
|
406
|
+
After loading the framework and any gems and plugins in your application, Rails turns to loading initializers. An initializer is any file of Ruby code stored under +config/initializers+ in your application. You can use initializers to hold configuration settings that should be made after all of the frameworks, plugins and gems are loaded, such as options to configure settings for these parts.
|
407
|
+
|
408
|
+
NOTE: You can use subfolders to organize your initializers if you like, because Rails will look into the whole file hierarchy from the initializers folder on down.
|
409
|
+
|
410
|
+
TIP: If you have any ordering dependency in your initializers, you can control the load order by naming. For example, +01_critical.rb+ will be loaded before +02_normal.rb+.
|
411
|
+
|
393
412
|
h3. Initialization events
|
394
413
|
|
395
414
|
Rails has 5 initialization events which can be hooked into (listed in order that they are ran):
|
@@ -398,7 +417,7 @@ Rails has 5 initialization events which can be hooked into (listed in order that
|
|
398
417
|
|
399
418
|
* +before_initialize+: This is run directly before the initialization process of the application occurs with the +:bootstrap_hook+ initializer near the beginning of the Rails initialization process.
|
400
419
|
|
401
|
-
* +to_prepare+: Run after the initializers are ran for all Railties (including the application itself), but before eager loading and the middleware stack is built.
|
420
|
+
* +to_prepare+: Run after the initializers are ran for all Railties (including the application itself), but before eager loading and the middleware stack is built.
|
402
421
|
|
403
422
|
* +before_eager_load+: This is run directly before eager loading occurs, which is the default behaviour for the _production_ environment and not for the +development+ enviroment.
|
404
423
|
|
@@ -412,12 +431,12 @@ h4. +Rails::Railtie#initializer+
|
|
412
431
|
Rails has several initializers that run on startup that are all defined by using the +initializer+ method from +Rails::Railtie+. Here's an example of the +initialize_whiny_nils+ initializer from Active Support:
|
413
432
|
|
414
433
|
<ruby>
|
415
|
-
|
416
|
-
|
417
|
-
|
434
|
+
initializer "active_support.initialize_whiny_nils" do |app|
|
435
|
+
require 'active_support/whiny_nil' if app.config.whiny_nils
|
436
|
+
end
|
418
437
|
</ruby>
|
419
438
|
|
420
|
-
The +initializer+ method takes three arguments with the first being the name for the initializer and the second being an options hash (not shown here) and the third being a block. The +:before+ key in the options hash can be specified to specify which initializer this new initializer must run before, and the +:after+ key will specify which initializer to run this initializer _after_.
|
439
|
+
The +initializer+ method takes three arguments with the first being the name for the initializer and the second being an options hash (not shown here) and the third being a block. The +:before+ key in the options hash can be specified to specify which initializer this new initializer must run before, and the +:after+ key will specify which initializer to run this initializer _after_.
|
421
440
|
|
422
441
|
Initializers defined using the +initializer+ method will be ran in the order they are defined in, with the exception of ones that use the +:before+ or +:after+ methods.
|
423
442
|
|
@@ -450,7 +469,7 @@ Serves as a placeholder so that +:load_environment_config+ can be defined to run
|
|
450
469
|
|
451
470
|
*+i18n.callbacks+* In the development environment, sets up a +to_prepare+ callback which will call +I18n.reload!+ if any of the locales have changed since the last request. In production mode this callback will only run on the first request.
|
452
471
|
|
453
|
-
*+active_support.initialize_whiny_nils+* Will require +active_support/whiny_nil+ if +config.
|
472
|
+
*+active_support.initialize_whiny_nils+* Will require +active_support/whiny_nil+ if +config.whiny_nils+ is set to +true+. This file will output errors such as:
|
454
473
|
|
455
474
|
<plain>
|
456
475
|
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
|
@@ -464,7 +483,7 @@ You might have expected an instance of Array.
|
|
464
483
|
The error occurred while evaluating nil.each
|
465
484
|
</plain>
|
466
485
|
|
467
|
-
*+active_support.deprecation_behavior+* Sets up deprecation reporting for environments, defaulting to
|
486
|
+
*+active_support.deprecation_behavior+* Sets up deprecation reporting for environments, defaulting to +:log+ for development, +:notify+ for production and +:stderr+ for test. If a value isn't set for +config.active_support.deprecation+ then this initializer will prompt the user to configure this line in the current environment's +config/environments+ file. Can be set to an array of values.
|
468
487
|
|
469
488
|
*+active_support.initialize_time_zone+* Sets the default time zone for the application based off the +config.time_zone+ setting, which defaults to "UTC".
|
470
489
|
|
@@ -544,8 +563,7 @@ TIP: If you have any ordering dependency in your initializers, you can control t
|
|
544
563
|
|
545
564
|
*+set_routes_reloader+* Configures Action Dispatch to reload the routes file using +ActionDispatch::Callbacks.to_prepare+.
|
546
565
|
|
547
|
-
*+disable_dependency_loading+*
|
548
|
-
|
566
|
+
*+disable_dependency_loading+* Disables the automatic dependency loading if the +config.cache_classes+ is set to +true+ and +config.dependency_loading+ is set to +false+.
|
549
567
|
|
550
568
|
h3. Changelog
|
551
569
|
|
@@ -7,14 +7,14 @@ endprologue.
|
|
7
7
|
h3. How to Contribute?
|
8
8
|
|
9
9
|
* We have an open commit policy: anyone is welcome to contribute and to review contributions.
|
10
|
-
* "docrails is hosted on GitHub":
|
10
|
+
* "docrails is hosted on GitHub":https://github.com/lifo/docrails and has public write access.
|
11
11
|
* Guides are written in Textile, and reside at +railties/guides/source+ in the docrails project.
|
12
|
-
* Follow the "Rails Guides Conventions":
|
12
|
+
* Follow the "Rails Guides Conventions":https://wiki.github.com/lifo/docrails/rails-guides-conventions.
|
13
13
|
* Assets are stored in the +railties/guides/assets+ directory.
|
14
|
-
* Sample format : "Active Record Associations":
|
14
|
+
* Sample format : "Active Record Associations":https://github.com/lifo/docrails/blob/3e56a3832415476fdd1cb963980d0ae390ac1ed3/railties/guides/source/association_basics.textile.
|
15
15
|
* Sample output : "Active Record Associations":association_basics.html.
|
16
|
-
* You can build the Guides during testing by running +rake generate_guides+ in the +railties+ directory.
|
17
|
-
* You're encouraged to validate XHTML for the generated guides before commiting your changes by running +rake validate_guides+ in the +railties+ directory.
|
16
|
+
* You can build the Guides during testing by running +bundle exec rake generate_guides+ in the +railties+ directory.
|
17
|
+
* You're encouraged to validate XHTML for the generated guides before commiting your changes by running +bundle exec rake validate_guides+ in the +railties+ directory.
|
18
18
|
* Edge guides "can be consulted online":http://edgeguides.rubyonrails.org/. That website is generated periodically from docrails.
|
19
19
|
|
20
20
|
h3. What to Contribute?
|
@@ -53,11 +53,11 @@ h3. Rules
|
|
53
53
|
* If the same guide writer wants to write multiple guides, that's ideally the situation we'd love to be in! However, that guide writer will only receive the cash prize for all the subsequent guides (and not the GitHub or RPM prizes).
|
54
54
|
* Our review team will have the final say on whether the guide is complete and of good enough quality.
|
55
55
|
|
56
|
-
All authors should read and follow the "Rails Guides Conventions":
|
56
|
+
All authors should read and follow the "Rails Guides Conventions":https://wiki.github.com/lifo/docrails/rails-guides-conventions and the "Rails API Documentation Conventions":https://wiki.github.com/lifo/docrails/rails-api-documentation-conventions.
|
57
57
|
|
58
58
|
h3. Translations
|
59
59
|
|
60
|
-
The translation effort for the Rails Guides is just getting underway. We know about projects to translate the Guides into Spanish, Portuguese, Polish, and French. For more details or to get involved see the "Translating Rails Guides":
|
60
|
+
The translation effort for the Rails Guides is just getting underway. We know about projects to translate the Guides into Spanish, Portuguese, Polish, and French. For more details or to get involved see the "Translating Rails Guides":https://wiki.github.com/lifo/docrails/translating-rails-guides page.
|
61
61
|
|
62
62
|
h3. Mailing List
|
63
63
|
|
@@ -24,7 +24,7 @@ If you've found a problem in Ruby on Rails which is not a security risk do a sea
|
|
24
24
|
|
25
25
|
At the minimum, your issue report needs a title and descriptive text. But that's only a minimum. You should include as much relevant information as possible. You need to at least post the code sample that has the issue. Even better is to include a unit test that shows how the expected behavior is not occurring. Your goal should be to make it easy for yourself - and others - to replicate the bug and figure out a fix.
|
26
26
|
|
27
|
-
Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kind of bug, you're creating this issue report in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the issue report will automatically see any activity or that others will jump to fix it. Creating
|
27
|
+
Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kind of bug, you're creating this issue report in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the issue report will automatically see any activity or that others will jump to fix it. Creating a issue like this is mostly to help yourself start on the path of fixing the problem and for others to confirm it with a "I'm having this problem too" comment.
|
28
28
|
|
29
29
|
h4. Special Treatment for Security Issues
|
30
30
|
|
@@ -90,7 +90,7 @@ This command will install all dependencies except the MySQL and PostgreSQL Ruby
|
|
90
90
|
$ rake test
|
91
91
|
</shell>
|
92
92
|
|
93
|
-
You can also run tests for
|
93
|
+
You can also run tests for an specific framework, like Action Pack, by going into its directory and executing the same command:
|
94
94
|
|
95
95
|
<shell>
|
96
96
|
$ cd actionpack
|
@@ -232,11 +232,11 @@ You can also help out by examining pull requests that have been submitted to Rub
|
|
232
232
|
$ git checkout -b testing_branch
|
233
233
|
</shell>
|
234
234
|
|
235
|
-
Then you can use their remote branch to update your codebase. For example, let's say the GitHub user JohnSmith has forked and pushed to the
|
235
|
+
Then you can use their remote branch to update your codebase. For example, let's say the GitHub user JohnSmith has forked and pushed to the master branch located at https://github.com/JohnSmith/rails.
|
236
236
|
|
237
237
|
<shell>
|
238
238
|
$ git remote add JohnSmith git://github.com/JohnSmith/rails.git
|
239
|
-
$ git pull JohnSmith
|
239
|
+
$ git pull JohnSmith master
|
240
240
|
</shell>
|
241
241
|
|
242
242
|
After applying their branch, test it out! Here are some things to think about:
|
@@ -264,7 +264,7 @@ When working with documentation, please take into account the "API Documentation
|
|
264
264
|
|
265
265
|
NOTE: As explained above, ordinary code patches should have proper documentation coverage. docrails is only used for isolated documentation improvements.
|
266
266
|
|
267
|
-
WARNING: docrails has a very strict policy: no code can be touched whatsoever, no matter how trivial or small the change. Only RDoc and guides can be edited via docrails.
|
267
|
+
WARNING: docrails has a very strict policy: no code can be touched whatsoever, no matter how trivial or small the change. Only RDoc and guides can be edited via docrails.
|
268
268
|
|
269
269
|
If you have an idea for a new guide you can refer to the "contribution page":contribute.html for instructions on getting involved.
|
270
270
|
|
@@ -300,16 +300,10 @@ h4. Follow the Coding Conventions
|
|
300
300
|
|
301
301
|
Rails follows a simple set of coding style conventions.
|
302
302
|
|
303
|
-
* Two spaces, no tabs
|
304
|
-
*
|
305
|
-
*
|
306
|
-
*
|
307
|
-
* Prefer class << self block over self.method for class methods.
|
308
|
-
* +MyClass.my_method(my_arg)+ not +my_method( my_arg )+ or +my_method my_arg+.
|
309
|
-
* a = b and not a=b.
|
310
|
-
* Follow the conventions you see used in the source already.
|
311
|
-
|
312
|
-
These are some guidelines and please use your best judgment in using them.
|
303
|
+
* Two spaces, no tabs
|
304
|
+
* Prefer +&&+/+||+ over +and+/+or+
|
305
|
+
* +MyClass.my_method(my_arg)+ not +my_method( my_arg )+ or +my_method my_arg+
|
306
|
+
* Follow the conventions you see used in the source already
|
313
307
|
|
314
308
|
h4. Sanity Check
|
315
309
|
|
@@ -350,22 +344,20 @@ Navigate to the Rails "GitHub repository":https://github.com/rails/rails and pre
|
|
350
344
|
Add the new remote to your local repository on your local machine:
|
351
345
|
|
352
346
|
<shell>
|
353
|
-
$ git remote add mine
|
347
|
+
$ git remote add mine https://<your user name>@github.com/<your user name>/rails.git
|
354
348
|
</shell>
|
355
349
|
|
356
350
|
Push to your remote:
|
357
351
|
|
358
352
|
<shell>
|
359
|
-
$ git push mine
|
353
|
+
$ git push mine master
|
360
354
|
</shell>
|
361
355
|
|
362
356
|
h4. Issue a Pull Request
|
363
357
|
|
364
|
-
Navigate to the Rails repository you just pushed to (e.g. https://github.com
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
Ensure the changesets you introduced are included in the "Commits" tab and that the "Files Changed" incorporate all of your changes.
|
358
|
+
Navigate to the Rails repository you just pushed to (e.g. https://github.com/<your user name>/rails) and press "Pull Request" in the upper right hand corner.
|
359
|
+
|
360
|
+
Ensure the changesets you introduced are included in the "Commits" tab and that the "Files Changed" incorporate all of your changes.
|
369
361
|
|
370
362
|
Fill in some details about your potential patch including a meaningful title. When finished, press "Send pull request." Rails Core will be notified about your submission.
|
371
363
|
|
@@ -385,7 +377,6 @@ All contributions, either via master or docrails, get credit in "Rails Contribut
|
|
385
377
|
|
386
378
|
h3. Changelog
|
387
379
|
|
388
|
-
* May 12, 2011: Modified to prefer topic branches instead of master branch for users contributions by "Guillermo Iguaran":http://quillarb.org
|
389
380
|
* April 29, 2011: Reflect GitHub Issues and Pull Request workflow by "Dan Pickett":http://www.enlightsolutions.com
|
390
381
|
* April 14, 2011: Modified Contributing to the Rails Code section to add '[#ticket_number state:commited]' on patches commit messages by "Sebastian Martinez":http://wyeworks.com
|
391
382
|
* December 28, 2010: Complete revision by "Xavier Noria":credits.html#fxn
|
@@ -20,7 +20,7 @@ Ruby on Rails Guides: Credits
|
|
20
20
|
<% end %>
|
21
21
|
|
22
22
|
<%= author('Xavier Noria', 'fxn', 'fxn.png') do %>
|
23
|
-
Xavier has been into Rails since 2005
|
23
|
+
Xavier Noria has been into Ruby on Rails since 2005. He is a Rails committer and enjoys combining his passion for Rails and his past life as a proofreader of math textbooks. Xavier is currently a Ruby on Rails consultant. Oh, he also <a href="http://twitter.com/fxn">tweets</a> and can be found everywhere as "fxn".
|
24
24
|
<% end %>
|
25
25
|
|
26
26
|
<h3 class="section">Rails Guides Designers</h3>
|
@@ -44,7 +44,7 @@ Ruby on Rails Guides: Credits
|
|
44
44
|
<% end %>
|
45
45
|
|
46
46
|
<%= author('Mikel Lindsaar', 'raasdnil') do %>
|
47
|
-
Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby <a href="
|
47
|
+
Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby <a href="https://github.com/mikel/mail">Mail gem</a> and core contributor (he helped re-write Action Mailer's API). Mikel is the founder of <a href="http://rubyx.com/">RubyX</a>, has a <a href="http://lindsaar.net/">blog</a> and <a href="http://twitter.com/raasdnil">tweets</a>.
|
48
48
|
<% end %>
|
49
49
|
|
50
50
|
<%= author('Cássio Marques', 'cmarques') do %>
|
@@ -52,7 +52,7 @@ Ruby on Rails Guides: Credits
|
|
52
52
|
<% end %>
|
53
53
|
|
54
54
|
<%= author('James Miller', 'bensie') do %>
|
55
|
-
James Miller is a software developer for <a href="http://www.jk-tech.com">JK Tech</a> in San Diego, CA.
|
55
|
+
James Miller is a software developer for <a href="http://www.jk-tech.com">JK Tech</a> in San Diego, CA. You can find James on GitHub, Gmail, Twitter, and Freenode as "bensie".
|
56
56
|
<% end %>
|
57
57
|
|
58
58
|
<%= author('Emilio Tagua', 'miloops') do %>
|
@@ -48,7 +48,7 @@ Title: Rails debugging guide
|
|
48
48
|
|
49
49
|
h4. +to_yaml+
|
50
50
|
|
51
|
-
Displaying an instance variable, or any other object or method, in
|
51
|
+
Displaying an instance variable, or any other object or method, in YAML format can be achieved this way:
|
52
52
|
|
53
53
|
<html>
|
54
54
|
<%= simple_format @post.to_yaml %>
|
@@ -96,33 +96,13 @@ Will be rendered as follows:
|
|
96
96
|
Title: Rails debugging guide
|
97
97
|
</pre>
|
98
98
|
|
99
|
-
h4. Debugging RJS
|
100
|
-
|
101
|
-
Rails has optional built-in support to debug RJS. When enabled, responses are wrapped in a try/catch block that displays the caught exception using +alert()+, and then re-raises it.
|
102
|
-
|
103
|
-
The flag to enable RJS debugging in your configuration files is +config.action_view.debug_rjs+:
|
104
|
-
|
105
|
-
<ruby>
|
106
|
-
config.action_view.debug_rjs = true
|
107
|
-
</ruby>
|
108
|
-
|
109
|
-
or at any time setting +ActionView::Base.debug_rjs+:
|
110
|
-
|
111
|
-
<ruby>
|
112
|
-
ActionView::Base.debug_rjs = true
|
113
|
-
</ruby>
|
114
|
-
|
115
|
-
It is enabled by default in development mode, and disabled in the rest.
|
116
|
-
|
117
|
-
TIP: For more information on debugging JavaScript, refer to "Firebug":http://getfirebug.com/, the popular debugger for Firefox.
|
118
|
-
|
119
99
|
h3. The Logger
|
120
100
|
|
121
101
|
It can also be useful to save information to log files at runtime. Rails maintains a separate log file for each runtime environment.
|
122
102
|
|
123
103
|
h4. What is the Logger?
|
124
104
|
|
125
|
-
Rails makes use of Ruby's standard +logger+ to write log information. You can also substitute another logger such as +
|
105
|
+
Rails makes use of Ruby's standard +logger+ to write log information. You can also substitute another logger such as +Log4r+ if you wish.
|
126
106
|
|
127
107
|
You can specify an alternative logger in your +environment.rb+ or any environment file:
|
128
108
|
|
@@ -178,7 +158,7 @@ class PostsController < ApplicationController
|
|
178
158
|
|
179
159
|
if @post.save
|
180
160
|
flash[:notice] = 'Post was successfully created.'
|
181
|
-
logger.debug "The post was saved and now
|
161
|
+
logger.debug "The post was saved and now the user is going to be redirected..."
|
182
162
|
redirect_to(@post)
|
183
163
|
else
|
184
164
|
render :action => "new"
|
@@ -204,7 +184,7 @@ Post should be valid: true
|
|
204
184
|
Post Create (0.000443) INSERT INTO "posts" ("updated_at", "title", "body", "published",
|
205
185
|
"created_at") VALUES('2008-09-08 14:52:54', 'Debugging Rails',
|
206
186
|
'I''m learning how to print in logs!!!', 'f', '2008-09-08 14:52:54')
|
207
|
-
The post was saved and now
|
187
|
+
The post was saved and now the user is going to be redirected...
|
208
188
|
Redirected to #<Post:0x20af760>
|
209
189
|
Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/posts]
|
210
190
|
</shell>
|
@@ -251,8 +231,8 @@ If you see the message in the console or logs:
|
|
251
231
|
Make sure you have started your web server with the option +--debugger+:
|
252
232
|
|
253
233
|
<shell>
|
254
|
-
|
255
|
-
=> Booting
|
234
|
+
$ rails server --debugger
|
235
|
+
=> Booting WEBrick
|
256
236
|
=> Rails 3.0.0 application starting on http://0.0.0.0:3000
|
257
237
|
=> Debugger enabled
|
258
238
|
...
|
@@ -260,8 +240,6 @@ Make sure you have started your web server with the option +--debugger+:
|
|
260
240
|
|
261
241
|
TIP: In development mode, you can dynamically +require \'ruby-debug\'+ instead of restarting the server, if it was started without +--debugger+.
|
262
242
|
|
263
|
-
In order to use Rails debugging you'll need to be running either *WEBrick* or *Mongrel*. For the moment, no alternative servers are supported.
|
264
|
-
|
265
243
|
h4. The Shell
|
266
244
|
|
267
245
|
As soon as your application calls the +debugger+ method, the debugger will be started in a debugger shell inside the terminal window where you launched your application server, and you will be placed at ruby-debug's prompt +(rdb:n)+. The _n_ is the thread number. The prompt will also show you the next line of code that is waiting to run.
|
@@ -271,7 +249,7 @@ If you got there by a browser request, the browser tab containing the request wi
|
|
271
249
|
For example:
|
272
250
|
|
273
251
|
<shell>
|
274
|
-
@posts = Post.
|
252
|
+
@posts = Post.all
|
275
253
|
(rdb:7)
|
276
254
|
</shell>
|
277
255
|
|
@@ -301,14 +279,14 @@ This command shows you where you are in the code by printing 10 lines centered a
|
|
301
279
|
[1, 10] in /PathToProject/posts_controller.rb
|
302
280
|
1 class PostsController < ApplicationController
|
303
281
|
2 # GET /posts
|
304
|
-
3 # GET /posts.
|
282
|
+
3 # GET /posts.json
|
305
283
|
4 def index
|
306
284
|
5 debugger
|
307
|
-
=> 6 @posts = Post.
|
285
|
+
=> 6 @posts = Post.all
|
308
286
|
7
|
309
287
|
8 respond_to do |format|
|
310
288
|
9 format.html # index.html.erb
|
311
|
-
10 format.
|
289
|
+
10 format.json { render :json => @posts }
|
312
290
|
</shell>
|
313
291
|
|
314
292
|
If you repeat the +list+ command, this time using just +l+, the next ten lines of the file will be printed out.
|
@@ -320,7 +298,7 @@ If you repeat the +list+ command, this time using just +l+, the next ten lines o
|
|
320
298
|
12 end
|
321
299
|
13
|
322
300
|
14 # GET /posts/1
|
323
|
-
15 # GET /posts/1.
|
301
|
+
15 # GET /posts/1.json
|
324
302
|
16 def show
|
325
303
|
17 @post = Post.find(params[:id])
|
326
304
|
18
|
@@ -330,6 +308,41 @@ If you repeat the +list+ command, this time using just +l+, the next ten lines o
|
|
330
308
|
|
331
309
|
And so on until the end of the current file. When the end of file is reached, the +list+ command will start again from the beginning of the file and continue again up to the end, treating the file as a circular buffer.
|
332
310
|
|
311
|
+
On the other hand, to see the previous ten lines you should type +list-+ (or +l-+)
|
312
|
+
|
313
|
+
<shell>
|
314
|
+
(rdb:7) l-
|
315
|
+
[1, 10] in /PathToProject/posts_controller.rb
|
316
|
+
1 class PostsController < ApplicationController
|
317
|
+
2 # GET /posts
|
318
|
+
3 # GET /posts.json
|
319
|
+
4 def index
|
320
|
+
5 debugger
|
321
|
+
6 @posts = Post.all
|
322
|
+
7
|
323
|
+
8 respond_to do |format|
|
324
|
+
9 format.html # index.html.erb
|
325
|
+
10 format.json { render :json => @posts }
|
326
|
+
</shell>
|
327
|
+
|
328
|
+
This way you can move inside the file, being able to see the code above and over the line you added the +debugger+.
|
329
|
+
Finally, to see where you are in the code again you can type +list=+
|
330
|
+
|
331
|
+
<shell>
|
332
|
+
(rdb:7) list=
|
333
|
+
[1, 10] in /PathToProject/posts_controller.rb
|
334
|
+
1 class PostsController < ApplicationController
|
335
|
+
2 # GET /posts
|
336
|
+
3 # GET /posts.json
|
337
|
+
4 def index
|
338
|
+
5 debugger
|
339
|
+
=> 6 @posts = Post.all
|
340
|
+
7
|
341
|
+
8 respond_to do |format|
|
342
|
+
9 format.html # index.html.erb
|
343
|
+
10 format.json { render :json => @posts }
|
344
|
+
</shell>
|
345
|
+
|
333
346
|
h4. The Context
|
334
347
|
|
335
348
|
When you start debugging your application, you will be placed in different contexts as you go through the different parts of the stack.
|
@@ -382,7 +395,7 @@ Any expression can be evaluated in the current context. To evaluate an expressio
|
|
382
395
|
This example shows how you can print the instance_variables defined within the current context:
|
383
396
|
|
384
397
|
<shell>
|
385
|
-
@posts = Post.
|
398
|
+
@posts = Post.all
|
386
399
|
(rdb:11) instance_variables
|
387
400
|
["@_response", "@action_name", "@url", "@_session", "@_cookies", "@performed_render", "@_flash", "@template", "@_params", "@before_filter_chain_aborted", "@request_origin", "@_headers", "@performed_redirect", "@_request"]
|
388
401
|
</shell>
|
@@ -479,7 +492,7 @@ end
|
|
479
492
|
TIP: You can use ruby-debug while using +rails console+. Just remember to +require "ruby-debug"+ before calling the +debugger+ method.
|
480
493
|
|
481
494
|
<shell>
|
482
|
-
|
495
|
+
$ rails console
|
483
496
|
Loading development environment (Rails 2.1.0)
|
484
497
|
>> require "ruby-debug"
|
485
498
|
=> []
|
@@ -603,7 +616,7 @@ There are some settings that can be configured in ruby-debug to make it easier t
|
|
603
616
|
|
604
617
|
You can see the full list by using +help set+. Use +help set _subcommand_+ to learn about a particular +set+ command.
|
605
618
|
|
606
|
-
TIP: You can include any number of these configuration lines inside a +.rdebugrc+ file in your HOME directory. ruby-debug will read this file every time it is loaded
|
619
|
+
TIP: You can include any number of these configuration lines inside a +.rdebugrc+ file in your HOME directory. ruby-debug will read this file every time it is loaded and configure itself accordingly.
|
607
620
|
|
608
621
|
Here's a good start for an +.rdebugrc+:
|
609
622
|
|
@@ -617,18 +630,18 @@ h3. Debugging Memory Leaks
|
|
617
630
|
|
618
631
|
A Ruby application (on Rails or not), can leak memory - either in the Ruby code or at the C code level.
|
619
632
|
|
620
|
-
In this section, you will learn how to find and fix such leaks by using
|
633
|
+
In this section, you will learn how to find and fix such leaks by using tools such as BleakHouse and Valgrind.
|
621
634
|
|
622
635
|
h4. BleakHouse
|
623
636
|
|
624
|
-
"BleakHouse":
|
637
|
+
"BleakHouse":https://github.com/fauna/bleak_house/tree/master is a library for finding memory leaks.
|
625
638
|
|
626
639
|
If a Ruby object does not go out of scope, the Ruby Garbage Collector won't sweep it since it is referenced somewhere. Leaks like this can grow slowly and your application will consume more and more memory, gradually affecting the overall system performance. This tool will help you find leaks on the Ruby heap.
|
627
640
|
|
628
641
|
To install it run:
|
629
642
|
|
630
643
|
<shell>
|
631
|
-
sudo gem install bleak_house
|
644
|
+
$ sudo gem install bleak_house
|
632
645
|
</shell>
|
633
646
|
|
634
647
|
Then setup your application for profiling. Then add the following at the bottom of config/environment.rb:
|
@@ -640,7 +653,7 @@ require 'bleak_house' if ENV['BLEAK_HOUSE']
|
|
640
653
|
Start a server instance with BleakHouse integration:
|
641
654
|
|
642
655
|
<shell>
|
643
|
-
RAILS_ENV=production BLEAK_HOUSE=1 ruby-bleak-house rails server
|
656
|
+
$ RAILS_ENV=production BLEAK_HOUSE=1 ruby-bleak-house rails server
|
644
657
|
</shell>
|
645
658
|
|
646
659
|
Make sure to run a couple hundred requests to get better data samples, then press +CTRL-C+. The server will stop and Bleak House will produce a dumpfile in +/tmp+:
|
@@ -670,7 +683,7 @@ To analyze it, just run the listed command. The top 20 leakiest lines will be li
|
|
670
683
|
|
671
684
|
This way you can find where your application is leaking memory and fix it.
|
672
685
|
|
673
|
-
If "BleakHouse":
|
686
|
+
If "BleakHouse":https://github.com/fauna/bleak_house/tree/master doesn't report any heap growth but you still have memory growth, you might have a broken C extension, or real leak in the interpreter. In that case, try using Valgrind to investigate further.
|
674
687
|
|
675
688
|
h4. Valgrind
|
676
689
|
|
@@ -684,12 +697,12 @@ h3. Plugins for Debugging
|
|
684
697
|
|
685
698
|
There are some Rails plugins to help you to find errors and debug your application. Here is a list of useful plugins for debugging:
|
686
699
|
|
687
|
-
* "Footnotes":
|
688
|
-
* "Query Trace":
|
689
|
-
* "Query Stats":
|
700
|
+
* "Footnotes":https://github.com/josevalim/rails-footnotes: Every Rails page has footnotes that give request information and link back to your source via TextMate.
|
701
|
+
* "Query Trace":https://github.com/ntalbott/query_trace/tree/master: Adds query origin tracing to your logs.
|
702
|
+
* "Query Stats":https://github.com/dan-manges/query_stats/tree/master: A Rails plugin to track database queries.
|
690
703
|
* "Query Reviewer":http://code.google.com/p/query-reviewer/: This rails plugin not only runs "EXPLAIN" before each of your select queries in development, but provides a small DIV in the rendered output of each page with the summary of warnings for each query that it analyzed.
|
691
|
-
* "Exception Notifier":
|
692
|
-
* "Exception Logger":
|
704
|
+
* "Exception Notifier":https://github.com/smartinez87/exception_notification/tree/master: Provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application.
|
705
|
+
* "Exception Logger":https://github.com/defunkt/exception_logger/tree/master: Logs your Rails exceptions in the database and provides a funky web interface to manage them.
|
693
706
|
|
694
707
|
h3. References
|
695
708
|
|