railties 3.1.0.beta1 → 3.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +47 -1
- data/guides/rails_guides/generator.rb +5 -4
- data/guides/source/action_controller_overview.textile +26 -0
- data/guides/source/active_support_core_extensions.textile +10 -0
- data/guides/source/association_basics.textile +2 -2
- data/guides/source/caching_with_rails.textile +30 -1
- data/guides/source/configuring.textile +40 -45
- data/guides/source/contributing_to_ruby_on_rails.textile +20 -11
- data/guides/source/generators.textile +23 -24
- data/guides/source/getting_started.textile +4 -4
- data/guides/source/layout.html.erb +1 -1
- data/guides/source/migrations.textile +1 -1
- data/guides/source/performance_testing.textile +159 -84
- data/guides/source/rails_on_rack.textile +0 -6
- data/guides/source/security.textile +5 -5
- data/guides/source/testing.textile +3 -3
- data/lib/rails/application.rb +12 -7
- data/lib/rails/application/bootstrap.rb +2 -1
- data/lib/rails/application/configuration.rb +1 -1
- data/lib/rails/commands.rb +2 -1
- data/lib/rails/commands/benchmarker.rb +28 -19
- data/lib/rails/commands/dbconsole.rb +1 -1
- data/lib/rails/commands/profiler.rb +27 -43
- data/lib/rails/commands/runner.rb +9 -15
- data/lib/rails/commands/server.rb +2 -1
- data/lib/rails/engine.rb +9 -2
- data/lib/rails/engine/configuration.rb +1 -0
- data/lib/rails/generators.rb +2 -2
- data/lib/rails/generators/actions.rb +1 -1
- data/lib/rails/generators/app_base.rb +24 -16
- data/lib/rails/generators/base.rb +2 -2
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +1 -1
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb +2 -2
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb +1 -1
- data/lib/rails/generators/generated_attribute.rb +7 -6
- data/lib/rails/generators/named_base.rb +2 -0
- data/lib/rails/generators/rails/app/app_generator.rb +15 -6
- data/lib/rails/generators/rails/app/templates/Gemfile +2 -1
- data/lib/rails/generators/rails/app/templates/README +10 -5
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +5 -2
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +3 -1
- data/lib/rails/generators/rails/app/templates/config/application.rb +3 -12
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +4 -1
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +3 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +3 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +4 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +4 -1
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +5 -2
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +4 -0
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +3 -0
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +0 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/gitignore +1 -0
- data/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb +4 -1
- data/lib/rails/generators/rails/assets/USAGE +3 -3
- data/lib/rails/generators/rails/assets/assets_generator.rb +4 -4
- data/lib/rails/generators/rails/controller/templates/controller.rb +1 -1
- data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +2 -1
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -2
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +1 -1
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml +3 -3
- data/lib/rails/generators/test_unit/performance/templates/performance_test.rb +4 -1
- data/lib/rails/rack.rb +4 -4
- data/lib/rails/rack/content_length.rb +38 -0
- data/lib/rails/railtie.rb +1 -0
- data/lib/rails/tasks/framework.rake +2 -7
- data/lib/rails/tasks/routes.rake +1 -1
- data/lib/rails/version.rb +1 -1
- metadata +6 -6
- data/lib/rails/rack/static.rb +0 -5
data/CHANGELOG
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
*Rails 3.1.0 (unreleased)*
|
2
2
|
|
3
|
+
* Application and plugin generation run bundle install unless --skip-gemfile or --skip-bundle. [fxn]
|
4
|
+
|
5
|
+
* Fixed database tasks for jdbc* adapters #jruby
|
6
|
+
|
7
|
+
[Rashmi Yadav]
|
8
|
+
|
9
|
+
* Template generation for jdbcpostgresql #jruby
|
10
|
+
|
11
|
+
[Vishnu Atrai]
|
12
|
+
|
13
|
+
* Template generation for jdbcmysql and jdbcsqlite3 #jruby
|
14
|
+
|
15
|
+
[Arun Agrawal]
|
16
|
+
|
3
17
|
* The -j option of the application generator accepts an arbitrary string. If passed "foo",
|
4
18
|
the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest
|
5
19
|
requires "foo" and "foo_ujs". As of this writing "prototype-rails" and "jquery-rails"
|
@@ -16,7 +30,7 @@ by the prototype-rails gem. [fxn]
|
|
16
30
|
|
17
31
|
* jQuery is the new default JavaScript library. [fxn]
|
18
32
|
|
19
|
-
* Changed scaffold and
|
33
|
+
* Changed scaffold, application, and mailer generator to create Ruby 1.9 style hash when running on Ruby 1.9 [Prem Sichanugrist]
|
20
34
|
|
21
35
|
So instead of creating something like:
|
22
36
|
|
@@ -62,10 +76,42 @@ by the prototype-rails gem. [fxn]
|
|
62
76
|
|
63
77
|
* Include all helpers from plugins and shared engines in application [Piotr Sarnacki]
|
64
78
|
|
79
|
+
|
80
|
+
*Rails 3.0.7 (April 18, 2011)*
|
81
|
+
|
82
|
+
*No changes.
|
83
|
+
|
84
|
+
|
85
|
+
*Rails 3.0.6 (April 5, 2011)
|
86
|
+
|
87
|
+
* No changes.
|
88
|
+
|
89
|
+
|
90
|
+
*Rails 3.0.5 (February 26, 2011)*
|
91
|
+
|
92
|
+
* No changes.
|
93
|
+
|
94
|
+
|
95
|
+
*Rails 3.0.4 (February 8, 2011)*
|
96
|
+
|
97
|
+
* No changes.
|
98
|
+
|
99
|
+
|
100
|
+
*Rails 3.0.3 (November 16, 2010)*
|
101
|
+
|
102
|
+
* No changes.
|
103
|
+
|
104
|
+
|
105
|
+
*Rails 3.0.2 (November 15, 2010)*
|
106
|
+
|
107
|
+
* No changes.
|
108
|
+
|
109
|
+
|
65
110
|
*Rails 3.0.1 (October 15, 2010)*
|
66
111
|
|
67
112
|
* No Changes, just a version bump.
|
68
113
|
|
114
|
+
|
69
115
|
*Rails 3.0.0 (August 29, 2010)*
|
70
116
|
|
71
117
|
* Application generation: --skip-testunit and --skip-activerecord become --skip-test-unit and --skip-active-record respectively. [fxn]
|
@@ -38,9 +38,10 @@
|
|
38
38
|
# Note that if you are working on a guide generation will by default process
|
39
39
|
# only that one, so ONLY is rarely used nowadays.
|
40
40
|
#
|
41
|
-
#
|
42
|
-
# Use
|
43
|
-
# folder (such as <tt>source/es</tt>).
|
41
|
+
# GUIDES_LANGUAGE
|
42
|
+
# Use GUIDES_LANGUAGE when you want to generate translated guides in
|
43
|
+
# <tt>source/<GUIDES_LANGUAGE></tt> folder (such as <tt>source/es</tt>).
|
44
|
+
# Ignore it when generating English guides.
|
44
45
|
#
|
45
46
|
# EDGE
|
46
47
|
# Set to "1" to indicate generated guides should be marked as edge. This
|
@@ -67,7 +68,7 @@ module RailsGuides
|
|
67
68
|
GUIDES_RE = /\.(?:textile|html\.erb)$/
|
68
69
|
|
69
70
|
def initialize(output=nil)
|
70
|
-
@lang = ENV['
|
71
|
+
@lang = ENV['GUIDES_LANGUAGE']
|
71
72
|
initialize_dirs(output)
|
72
73
|
create_output_dir_if_needed
|
73
74
|
set_flags_from_environment
|
@@ -110,6 +110,32 @@ When this form is submitted, the value of +params[:client]+ will be <tt>{"name"
|
|
110
110
|
|
111
111
|
Note that the +params+ hash is actually an instance of +HashWithIndifferentAccess+ from Active Support, which acts like a hash that lets you use symbols and strings interchangeably as keys.
|
112
112
|
|
113
|
+
h4. JSON/XML parameters
|
114
|
+
|
115
|
+
If you're writing a web service application, you might find yourself more comfortable on accepting parameters in JSON or XML format. Rails will automatically convert your parameters into +params+ hash, which you'll be able to access like you would normally do with form data.
|
116
|
+
|
117
|
+
So for example, if you are sending this JSON parameter:
|
118
|
+
|
119
|
+
<pre>
|
120
|
+
{ "company": { "name": "acme", "address": "123 Carrot Street" } }
|
121
|
+
</pre>
|
122
|
+
|
123
|
+
You'll get <tt>params[:company]</tt> as <tt>{ :name => "acme", "address" => "123 Carrot Street" }</tt>.
|
124
|
+
|
125
|
+
Also, if you've turned on +config.wrap_parameters+ in your initializer or calling +wrap_parameters+ in your controller, you can safely omit the root element in the JSON/XML parameter. The parameters will be cloned and wrapped in the key according to your controller's name by default. So the above parameter can be written as:
|
126
|
+
|
127
|
+
<pre>
|
128
|
+
{ "name": "acme", "address": "123 Carrot Street" }
|
129
|
+
</pre>
|
130
|
+
|
131
|
+
And assume that you're sending the data to +CompaniesController+, it would then be wrapped in +:company+ key like this:
|
132
|
+
|
133
|
+
<ruby>
|
134
|
+
{ :name => "acme", :address => "123 Carrot Street", :company => { :name => "acme", :address => "123 Carrot Street" }}
|
135
|
+
</ruby>
|
136
|
+
|
137
|
+
You can customize the name of the key or specific parameters you want to wrap by consulting the "API documentation":http://api.rubyonrails.org/classes/ActionController/ParamsWrapper.html
|
138
|
+
|
113
139
|
h4. Routing Parameters
|
114
140
|
|
115
141
|
The +params+ hash will always contain the +:controller+ and +:action+ keys, but you should use the methods +controller_name+ and +action_name+ instead to access these values. Any other parameters defined by the routing, such as +:id+ will also be available. As an example, consider a listing of clients where the list can show either active or inactive clients. We can add a route which captures the +:status+ parameter in a "pretty" URL:
|
@@ -417,6 +417,14 @@ silence_stream(STDOUT) do
|
|
417
417
|
end
|
418
418
|
</ruby>
|
419
419
|
|
420
|
+
The +quietly+ method addresses the common use case where you want to silence STDOUT and STDERR, even in subprocesses:
|
421
|
+
|
422
|
+
<ruby>
|
423
|
+
quietly { system 'bundle install' }
|
424
|
+
</ruby>
|
425
|
+
|
426
|
+
For example, the railties test suite uses that one in a few places to prevent command messages from being echoed intermixed with the progress status.
|
427
|
+
|
420
428
|
Silencing exceptions is also possible with +suppress+. This method receives an arbitrary number of exception classes. If an exception is raised during the execution of the block and is +kind_of?+ any of the arguments, +suppress+ captures it and returns silently. Otherwise the exception is reraised:
|
421
429
|
|
422
430
|
<ruby>
|
@@ -1833,6 +1841,8 @@ The method +ordinalize+ returns the ordinal string corresponding to the receiver
|
|
1833
1841
|
2.ordinalize # => "2nd"
|
1834
1842
|
53.ordinalize # => "53rd"
|
1835
1843
|
2009.ordinalize # => "2009th"
|
1844
|
+
-21.ordinalize # => "-21st"
|
1845
|
+
-134.ordinalize # => "-134th"
|
1836
1846
|
</ruby>
|
1837
1847
|
|
1838
1848
|
NOTE: Defined in +active_support/core_ext/integer/inflections.rb+.
|
@@ -342,9 +342,9 @@ In designing a data model, you will sometimes find a model that should have a re
|
|
342
342
|
|
343
343
|
<ruby>
|
344
344
|
class Employee < ActiveRecord::Base
|
345
|
-
has_many :subordinates, :class_name => "Employee"
|
345
|
+
has_many :subordinates, :class_name => "Employee"
|
346
|
+
belongs_to :manager, :class_name => "Employee",
|
346
347
|
:foreign_key => "manager_id"
|
347
|
-
belongs_to :manager, :class_name => "Employee"
|
348
348
|
end
|
349
349
|
</ruby>
|
350
350
|
|
@@ -98,7 +98,7 @@ You can also use +:if+ (or +:unless+) to pass a Proc that specifies when the act
|
|
98
98
|
|
99
99
|
You can modify the default action cache path by passing a +:cache_path+ option. This will be passed directly to +ActionCachePath.path_for+. This is handy for actions with multiple possible routes that should be cached differently. If a block is given, it is called with the current controller instance.
|
100
100
|
|
101
|
-
Finally, if you are using memcached, you can also pass +:expires_in+. In fact, all parameters not used by +caches_action+ are sent to the underlying cache store.
|
101
|
+
Finally, if you are using memcached or Ehcache, you can also pass +:expires_in+. In fact, all parameters not used by +caches_action+ are sent to the underlying cache store.
|
102
102
|
|
103
103
|
INFO: Action caching runs in an after filter. Thus, invalid requests won't generate spurious cache entries as long as you halt them. Typically, a redirection in some before filter that checks request preconditions does the job.
|
104
104
|
|
@@ -304,6 +304,35 @@ The +write+ and +fetch+ methods on this cache accept two additional options that
|
|
304
304
|
ActionController::Base.cache_store = :mem_cache_store, "cache-1.example.com", "cache-2.example.com"
|
305
305
|
</ruby>
|
306
306
|
|
307
|
+
h4. ActiveSupport::Cache::EhcacheStore
|
308
|
+
|
309
|
+
If you are using JRuby you can use Terracotta's Ehcache as the cache store for your application. Ehcache is an open source Java cache that also offers an enterprise version with increased scalability, management, and commercial support. You must first install the jruby-ehcache-rails3 gem (version 1.1.0 or later) to use this cache store.
|
310
|
+
|
311
|
+
<ruby>
|
312
|
+
ActionController::Base.cache_store = :ehcache_store
|
313
|
+
</ruby>
|
314
|
+
|
315
|
+
When initializing the cache, you may use the +:ehcache_config+ option to specify the Ehcache config file to use (where the default is "ehcache.xml" in your Rails config directory), and the :cache_name option to provide a custom name for your cache (the default is rails_cache).
|
316
|
+
|
317
|
+
In addition to the standard +:expires_in+ option, the +write+ method on this cache can also accept the additional +:unless_exist+ option, which will cause the cache store to use Ehcache's +putIfAbsent+ method instead of +put+, and therefore will not overwrite an existing entry. Additionally, the +write+ method supports all of the properties exposed by the "Ehcache Element class":http://ehcache.org/apidocs/net/sf/ehcache/Element.html , including:
|
318
|
+
|
319
|
+
|_. Property |_. Argument Type |_. Description |
|
320
|
+
| elementEvictionData | ElementEvictionData | Sets this element's eviction data instance. |
|
321
|
+
| eternal | boolean | Sets whether the element is eternal. |
|
322
|
+
| timeToIdle, tti | int | Sets time to idle |
|
323
|
+
| timeToLive, ttl, expires_in | int | Sets time to Live |
|
324
|
+
| version | long | Sets the version attribute of the ElementAttributes object. |
|
325
|
+
|
326
|
+
These options are passed to the +write+ method as Hash options using either camelCase or underscore notation, as in the following examples:
|
327
|
+
|
328
|
+
<ruby>
|
329
|
+
Rails.cache.write('key', 'value', :time_to_idle => 60.seconds, :timeToLive => 600.seconds)
|
330
|
+
caches_action :index, :expires_in => 60.seconds, :unless_exist => true
|
331
|
+
</ruby>
|
332
|
+
|
333
|
+
For more information about Ehcache, see "http://ehcache.org/":http://ehcache.org/ .
|
334
|
+
For more information about Ehcache for JRuby and Rails, see "http://ehcache.org/documentation/jruby.html":http://ehcache.org/documentation/jruby.html
|
335
|
+
|
307
336
|
h4. Custom Cache Stores
|
308
337
|
|
309
338
|
You can create your own custom cache store by simply extending +ActiveSupport::Cache::Store+ and implementing the appropriate methods. In this way, you can swap in any number of caching technologies into your Rails application.
|
@@ -9,37 +9,38 @@ endprologue.
|
|
9
9
|
|
10
10
|
h3. Locations for Initialization Code
|
11
11
|
|
12
|
-
Rails offers
|
12
|
+
Rails offers four standard spots to place initialization code:
|
13
13
|
|
14
|
-
* application.rb
|
15
|
-
* Environment-specific
|
14
|
+
* +config/application.rb+
|
15
|
+
* Environment-specific configuration files
|
16
16
|
* Initializers
|
17
|
-
* After-
|
17
|
+
* After-initializers
|
18
18
|
|
19
19
|
h3. Running Code Before Rails
|
20
20
|
|
21
|
-
|
22
|
-
+require 'rails/all'+ in your +application.rb+.
|
21
|
+
In the rare event that your application needs to run some code before Rails itself is loaded, put it above the call to +require 'rails/all'+ in your +config/application.rb+.
|
23
22
|
|
24
23
|
h3. Configuring Rails Components
|
25
24
|
|
26
|
-
In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The +application.rb+ and environment-specific configuration files (such as +config/environments/production.rb+) allow you to specify the various settings that you want to pass down to all of the components.
|
25
|
+
In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The configuration file +config/application.rb+ and environment-specific configuration files (such as +config/environments/production.rb+) allow you to specify the various settings that you want to pass down to all of the components.
|
26
|
+
|
27
|
+
For example, the default +config/application.rb+ file includes this setting:
|
27
28
|
|
28
29
|
<ruby>
|
29
|
-
|
30
|
+
config.filter_parameters += [:password]
|
30
31
|
</ruby>
|
31
32
|
|
32
|
-
This is a setting for Rails itself. If you want to pass settings to individual Rails components, you can do so via the same +config+ object
|
33
|
+
This is a setting for Rails itself. If you want to pass settings to individual Rails components, you can do so via the same +config+ object in +config/application.rb+:
|
33
34
|
|
34
35
|
<ruby>
|
35
|
-
|
36
|
+
config.active_record.observers = [:hotel_observer, :review_observer]
|
36
37
|
</ruby>
|
37
38
|
|
38
39
|
Rails will use that particular setting to configure Active Record.
|
39
40
|
|
40
41
|
h4. Rails General Configuration
|
41
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
|
+
* +config.after_initialize+ takes a block which will be ran _after_ Rails has finished initializing the application. That includes the initialization of the framework itself, plugins, engines, and all the application's initializers in +config/initializers+. Useful for configuring values set up by other initializers:
|
43
44
|
|
44
45
|
<ruby>
|
45
46
|
config.after_initialize do
|
@@ -47,71 +48,63 @@ config.after_initialize do
|
|
47
48
|
end
|
48
49
|
</ruby>
|
49
50
|
|
50
|
-
* +config.allow_concurrency+ should be
|
51
|
+
* +config.allow_concurrency+ should be true to allow concurrent (threadsafe) action processing. 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!+.
|
51
52
|
|
52
|
-
* +config.asset_host+ sets the host for the assets. Useful when CDNs are used for hosting assets
|
53
|
+
* +config.asset_host+ sets the host for the assets. Useful when CDNs are used for hosting assets, or when you want to work around the concurrency constraints builtin in browsers using different domain aliases. Shorter version of +config.action_controller.asset_host+.
|
53
54
|
|
54
|
-
* +config.asset_path+
|
55
|
+
* +config.asset_path+ can take a callable, a string, or be +nil+. Default is +nil+. If set, this configuration parameter let's you decorate asset paths. For example, the normal path for +blog.js+ would be +/javascripts/blog.js+, let that absolute path be +path+. If +config.asset_path+ is a callable, Rails calls it when generating asset paths passing +path+ as argument. If +config.asset_path+ is a string, it is expected to be a +sprintf+ format string with a +%s+ where +path+ will get inserted. In either case, Rails outputs the decorated path. *This option is ignored if the asset pipeline is enabled, which is by default*. Shorter version of +config.action_controller.asset_path+.
|
55
56
|
|
56
57
|
<ruby>
|
57
|
-
|
58
|
+
config.asset_path = proc { |path| "/blog/public#{path}" }
|
58
59
|
</ruby>
|
59
60
|
|
60
|
-
* +config.autoload_once_paths+ accepts an array of paths from which Rails will
|
61
|
-
|
62
|
-
* +config.autoload_paths+ accepts an array of additional paths to prepend to the load path. By default, all app, lib, vendor and mock paths are included in this list.
|
61
|
+
* +config.autoload_once_paths+ accepts an array of paths from which Rails will autoload constants that won't be wiped per request. Relevant if +config.cache_classes+ is false, which is the case in development mode by default. Otherwise, all autoloading happens only once. All elements of this array must also be in +autoload_paths+. Default is an empty array.
|
63
62
|
|
64
|
-
* +config.
|
63
|
+
* +config.autoload_paths+ accepts an array of paths from which Rails will autoload constants. Default is all directories under +app+.
|
65
64
|
|
66
|
-
* +config.
|
65
|
+
* +config.cache_classes+ controls whether or not application classes and modules should be reloaded on each request. Defaults to true in development mode, and false in test and production modes. Can also be enabled with +threadsafe!+.
|
67
66
|
|
68
|
-
* +config.
|
67
|
+
* +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+.
|
69
68
|
|
70
|
-
* +config.
|
69
|
+
* +config.cache_store+ configures which cache store to use for Rails caching. Options include one of the symbols +:memory_store+, +:file_store+, +:mem_cache_store+, or an object that implements the cache API. Defaults to +:file_store+ if the directory +tmp/cache+ exists, and to +:memory_store+ otherwise.
|
71
70
|
|
72
|
-
* +config.
|
71
|
+
* +config.colorize_logging+ specifies whether or not to use ANSI color codes when logging information. Defaults to true.
|
73
72
|
|
74
|
-
* +config.
|
73
|
+
* +config.consider_all_requests_local+ is a flag. If true then any error will cause detailed debugging information to be dumped in the HTTP response, and the +Rails::Info+ controller will show the application runtime context in +/rails/info/properties+. True by default in development and test environments, and false in production mode. For finer-grained control, set this to false and implement +local_request?+ in controllers to specify which requests should provide debugging information on errors.
|
75
74
|
|
76
|
-
* +config.dependency_loading+
|
75
|
+
* +config.dependency_loading+ is a flag that allows you to disable constant autoloading setting it to false. It only has effect if +config.cache_classes+ is true, which it is by default in production mode. This flag is set to false by +config.threadsafe!+.
|
77
76
|
|
78
|
-
* +config.eager_load_paths+ accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the +app+ directory of the application.
|
77
|
+
* +config.eager_load_paths+ accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the +app+ directory of the application.
|
79
78
|
|
80
79
|
* +config.encoding+ sets up the application-wide encoding. Defaults to UTF-8.
|
81
80
|
|
82
81
|
* +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.
|
83
82
|
|
84
|
-
* +config.force_ssl+
|
85
|
-
|
86
|
-
* +config.helper_paths+ configures where Rails can find helpers for this application.
|
83
|
+
* +config.force_ssl+ forces all requests to be under HTTPS protocol by using +Rack::SSL+ middleware.
|
87
84
|
|
88
|
-
* +config.log_level+ defines the verbosity of the Rails logger.
|
85
|
+
* +config.log_level+ defines the verbosity of the Rails logger. This option defaults to +:debug+ for all modes except production, where it defaults to +:info+.
|
89
86
|
|
90
|
-
* +config.
|
87
|
+
* +config.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ +Logger+ class. Defaults to an instance of +ActiveSupport::BufferedLogger+, with auto flushing off in production mode.
|
91
88
|
|
92
|
-
* +config.
|
89
|
+
* +config.middleware+ allows you to configure the application's middleware. This is covered in depth in the "Configuring Middleware":configuring-middleware section below.
|
93
90
|
|
94
|
-
* +config.
|
91
|
+
* +config.plugins+ accepts the list of plugins to load. If this is set to +nil+, default, all plugins will be loaded. If this is set to +[]+, no plugins will be loaded. Otherwise, plugins will be loaded in the order specified. This option let's you enforce some particular loading order, useful when dependencies between plugins require it. For that use case, put first the plugins you want to be loaded in a certain order, and then the special symbol +:all+ to have the rest loaded without the need to specify them.
|
95
92
|
|
96
|
-
* +config.
|
93
|
+
* +config.preload_frameworks+ enables or disables preloading all frameworks at startup. Enabled by +config.threadsafe!+. Defaults to +nil+, so is disabled.
|
97
94
|
|
98
|
-
* +config.
|
95
|
+
* +config.reload_plugins+ enables or disables plugin reloading. Defaults to false.
|
99
96
|
|
100
|
-
* +config.
|
97
|
+
* +config.secret_token+ used for specifying a key which allows sessions for the application to be verified against a known secure key to prevent tampering. Applications get +config.secret_token+ initialized to a random key in +config/initializers/secret_token.rb+.
|
101
98
|
|
102
|
-
* +config.
|
99
|
+
* +config.serve_static_assets+ configures Rails to serve static assets. Defaults to true, but in the production environment is turned off. The server software used to run the application should be used to serve the assets instead.
|
103
100
|
|
104
|
-
* +config.
|
105
|
-
|
106
|
-
* +config.serve_static_assets+ configures Rails to serve static assets. Defaults to _true_, but in the production environment is turned off. The server software used to run the application should be used to serve the assets instead.
|
107
|
-
|
108
|
-
* +config.session_store+ is usually set up in +config/initializers/session_store.rb+ and specifies what class to use to store the session. Custom session stores can be specified like so:
|
101
|
+
* +config.session_store+ is usually set up in +config/initializers/session_store.rb+ and specifies what class to use to store the session. Possible values are +:cookie_store+, default, +:mem_cache_store+, and +:disabled+. The last one tells Rails not to deal with sessions. Custom session stores can also be specified like so:
|
109
102
|
|
110
103
|
<ruby>
|
111
|
-
|
104
|
+
config.session_store :my_custom_store
|
112
105
|
</ruby>
|
113
106
|
|
114
|
-
This custom store must be defined as +ActionDispatch::Session::MyCustomStore+.
|
107
|
+
This custom store must be defined as +ActionDispatch::Session::MyCustomStore+. In addition to symbols, they can also be objects implementing a certain API, like +ActiveRecord::SessionStore+, in which case no special namespace is required.
|
115
108
|
|
116
109
|
* +config.threadsafe!+ enables +allow_concurrency+, +cache_classes+, +dependency_loading+ and +preload_frameworks+ to make the application threadsafe.
|
117
110
|
|
@@ -119,7 +112,9 @@ WARNING: Threadsafe operation is incompatible with the normal workings of develo
|
|
119
112
|
|
120
113
|
* +config.time_zone+ sets the default time zone for the application and enables time zone awareness for Active Record.
|
121
114
|
|
122
|
-
* +config.whiny_nils+ enables or disables warnings when
|
115
|
+
* +config.whiny_nils+ enables or disables warnings when a certain set of methods are invoked on +nil+ and it does not respond to them. Defaults to true in development and test environments.
|
116
|
+
|
117
|
+
* +config.assets.enabled+ a flag that controls whether the asset pipeline is enabled. It is explicitly initialized in +config/application.rb+.
|
123
118
|
|
124
119
|
h4. Configuring Generators
|
125
120
|
|
@@ -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 topic 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 topic
|
240
240
|
</shell>
|
241
241
|
|
242
242
|
After applying their branch, test it out! Here are some things to think about:
|
@@ -300,10 +300,16 @@ 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
|
-
*
|
303
|
+
* Two spaces, no tabs.
|
304
|
+
* No trailing whitespace. Blank lines should not have any space.
|
305
|
+
* Indent after private/protected.
|
306
|
+
* Prefer +&&+/+||+ over +and+/+or+.
|
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 judgement in using them.
|
307
313
|
|
308
314
|
h4. Sanity Check
|
309
315
|
|
@@ -344,20 +350,22 @@ Navigate to the Rails "GitHub repository":https://github.com/rails/rails and pre
|
|
344
350
|
Add the new remote to your local repository on your local machine:
|
345
351
|
|
346
352
|
<shell>
|
347
|
-
$ git remote add mine https
|
353
|
+
$ git remote add mine https://<your user name>@github.com/<your user name>/rails.git
|
348
354
|
</shell>
|
349
355
|
|
350
356
|
Push to your remote:
|
351
357
|
|
352
358
|
<shell>
|
353
|
-
$ git push mine
|
359
|
+
$ git push mine my_new_branch
|
354
360
|
</shell>
|
355
361
|
|
356
362
|
h4. Issue a Pull Request
|
357
363
|
|
358
|
-
Navigate to the Rails repository you just pushed to (e.g. https://github.com
|
359
|
-
|
360
|
-
|
364
|
+
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.
|
365
|
+
|
366
|
+
Write your branch name in branch field (is filled with master by default) and press "Update Commit Range"
|
367
|
+
|
368
|
+
Ensure the changesets you introduced are included in the "Commits" tab and that the "Files Changed" incorporate all of your changes.
|
361
369
|
|
362
370
|
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.
|
363
371
|
|
@@ -377,6 +385,7 @@ All contributions, either via master or docrails, get credit in "Rails Contribut
|
|
377
385
|
|
378
386
|
h3. Changelog
|
379
387
|
|
388
|
+
* May 12, 2011: Modified to prefer topic branches instead of master branch for users contributions by "Guillermo Iguaran":http://quillarb.org
|
380
389
|
* April 29, 2011: Reflect GitHub Issues and Pull Request workflow by "Dan Pickett":http://www.enlightsolutions.com
|
381
390
|
* 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
|
382
391
|
* December 28, 2010: Complete revision by "Xavier Noria":credits.html#fxn
|
@@ -111,7 +111,6 @@ In order to understand what a generator template means, let's create the file +l
|
|
111
111
|
|
112
112
|
<ruby>
|
113
113
|
# Add initialization content here
|
114
|
-
|
115
114
|
</ruby>
|
116
115
|
|
117
116
|
And now let's change the generator to copy this template when invoked:
|
@@ -286,8 +285,8 @@ end
|
|
286
285
|
Now, when the helper generator is invoked and TestUnit is configured as the test framework, it will try to invoke both +Rails::TestUnitGenerator+ and +TestUnit::MyHelperGenerator+. Since none of those are defined, we can tell our generator to invoke +TestUnit::Generators::HelperGenerator+ instead, which is defined since it's a Rails generator. To do that, we just need to add:
|
287
286
|
|
288
287
|
<ruby>
|
289
|
-
|
290
|
-
|
288
|
+
# Search for :helper instead of :my_helper
|
289
|
+
hook_for :test_framework, :as => :helper
|
291
290
|
</ruby>
|
292
291
|
|
293
292
|
And now you can re-run scaffold for another resource and see it generating tests as well!
|
@@ -412,7 +411,7 @@ h4. +plugin+
|
|
412
411
|
+plugin+ will install a plugin into the current application.
|
413
412
|
|
414
413
|
<ruby>
|
415
|
-
|
414
|
+
plugin("dynamic-form", :git => "git://github.com/rails/dynamic-form.git")
|
416
415
|
</ruby>
|
417
416
|
|
418
417
|
Available options are:
|
@@ -441,13 +440,13 @@ Available options are:
|
|
441
440
|
Any additional options passed to this method are put on the end of the line:
|
442
441
|
|
443
442
|
<ruby>
|
444
|
-
|
443
|
+
gem("devise", :git => "git://github.com/plataformatec/devise", :branch => "master")
|
445
444
|
</ruby>
|
446
445
|
|
447
446
|
The above code will put the following line into +Gemfile+:
|
448
447
|
|
449
448
|
<ruby>
|
450
|
-
|
449
|
+
gem "devise", :git => "git://github.com/plataformatec/devise", :branch => "master"
|
451
450
|
</ruby>
|
452
451
|
|
453
452
|
|
@@ -456,7 +455,7 @@ h4. +add_source+
|
|
456
455
|
Adds a specified source to +Gemfile+:
|
457
456
|
|
458
457
|
<ruby>
|
459
|
-
|
458
|
+
add_source "http://gems.github.com"
|
460
459
|
</ruby>
|
461
460
|
|
462
461
|
h4. +application+
|
@@ -464,7 +463,7 @@ h4. +application+
|
|
464
463
|
Adds a line to +config/application.rb+ directly after the application class definition.
|
465
464
|
|
466
465
|
<ruby>
|
467
|
-
|
466
|
+
application "config.asset_host = 'http://example.com'"
|
468
467
|
</ruby>
|
469
468
|
|
470
469
|
This method can also take a block:
|
@@ -490,10 +489,10 @@ h4. +git+
|
|
490
489
|
Runs the specified git command:
|
491
490
|
|
492
491
|
<ruby>
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
492
|
+
git :init
|
493
|
+
git :add => "."
|
494
|
+
git :commit => "-m First commit!"
|
495
|
+
git :add => "onefile.rb", :rm => "badfile.cxx"
|
497
496
|
</ruby>
|
498
497
|
|
499
498
|
The values of the hash here being the arguments or options passed to the specific git command. As per the final example shown here, multiple git commands can be specified at a time, but the order of their running is not guaranteed to be the same as the order that they were specified in.
|
@@ -503,15 +502,15 @@ h4. +vendor+
|
|
503
502
|
Places a file into +vendor+ which contains the specified code.
|
504
503
|
|
505
504
|
<ruby>
|
506
|
-
|
505
|
+
vendor("sekrit.rb", '#top secret stuff')
|
507
506
|
</ruby>
|
508
507
|
|
509
508
|
This method also takes a block:
|
510
509
|
|
511
510
|
<ruby>
|
512
|
-
|
513
|
-
|
514
|
-
|
511
|
+
vendor("seeds.rb") do
|
512
|
+
"puts 'in ur app, seeding ur database'"
|
513
|
+
end
|
515
514
|
</ruby>
|
516
515
|
|
517
516
|
h4. +lib+
|
@@ -519,7 +518,7 @@ h4. +lib+
|
|
519
518
|
Places a file into +lib+ which contains the specified code.
|
520
519
|
|
521
520
|
<ruby>
|
522
|
-
|
521
|
+
lib("special.rb", 'p Rails.root')
|
523
522
|
</ruby>
|
524
523
|
|
525
524
|
This method also takes a block:
|
@@ -535,7 +534,7 @@ h4. +rakefile+
|
|
535
534
|
Creates a Rake file in the +lib/tasks+ directory of the application.
|
536
535
|
|
537
536
|
<ruby>
|
538
|
-
|
537
|
+
rakefile("test.rake", 'hello there')
|
539
538
|
</ruby>
|
540
539
|
|
541
540
|
This method also takes a block:
|
@@ -555,7 +554,7 @@ h4. +initializer+
|
|
555
554
|
Creates an initializer in the +config/initializers+ directory of the application:
|
556
555
|
|
557
556
|
<ruby>
|
558
|
-
|
557
|
+
initializer("begin.rb", "puts 'this is the beginning'")
|
559
558
|
</ruby>
|
560
559
|
|
561
560
|
This method also takes a block:
|
@@ -571,7 +570,7 @@ h4. +generate+
|
|
571
570
|
Runs the specified generator where the first argument is the generator name and the remaining arguments are passed directly to the generator.
|
572
571
|
|
573
572
|
<ruby>
|
574
|
-
|
573
|
+
generate("scaffold", "forums title:string description:text")
|
575
574
|
</ruby>
|
576
575
|
|
577
576
|
|
@@ -580,7 +579,7 @@ h4. +rake+
|
|
580
579
|
Runs the specified Rake task.
|
581
580
|
|
582
581
|
<ruby>
|
583
|
-
|
582
|
+
rake("db:migrate")
|
584
583
|
</ruby>
|
585
584
|
|
586
585
|
Available options are:
|
@@ -593,7 +592,7 @@ h4. +capify!+
|
|
593
592
|
Runs the +capify+ command from Capistrano at the root of the application which generates Capistrano configuration.
|
594
593
|
|
595
594
|
<ruby>
|
596
|
-
|
595
|
+
capify!
|
597
596
|
</ruby>
|
598
597
|
|
599
598
|
h4. +route+
|
@@ -601,7 +600,7 @@ h4. +route+
|
|
601
600
|
Adds text to the +config/routes.rb+ file:
|
602
601
|
|
603
602
|
<ruby>
|
604
|
-
|
603
|
+
route("resources :people")
|
605
604
|
</ruby>
|
606
605
|
|
607
606
|
h4. +readme+
|
@@ -609,7 +608,7 @@ h4. +readme+
|
|
609
608
|
Output the contents of a file in the template's +source_path+, usually a README.
|
610
609
|
|
611
610
|
<ruby>
|
612
|
-
|
611
|
+
readme("README")
|
613
612
|
</ruby>
|
614
613
|
|
615
614
|
h3. Changelog
|