railties 3.1.0.rc4 → 3.1.0.rc5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/CHANGELOG +7 -9
  2. data/bin/rails +2 -0
  3. data/guides/assets/images/rails_welcome.png +0 -0
  4. data/guides/rails_guides/generator.rb +1 -1
  5. data/guides/rails_guides/textile_extensions.rb +18 -17
  6. data/guides/source/3_0_release_notes.textile +21 -21
  7. data/guides/source/action_controller_overview.textile +1 -1
  8. data/guides/source/action_mailer_basics.textile +27 -6
  9. data/guides/source/action_view_overview.textile +6 -6
  10. data/guides/source/active_record_querying.textile +77 -7
  11. data/guides/source/active_record_validations_callbacks.textile +78 -81
  12. data/guides/source/active_support_core_extensions.textile +87 -31
  13. data/guides/source/ajax_on_rails.textile +1 -1
  14. data/guides/source/api_documentation_guidelines.textile +12 -8
  15. data/guides/source/asset_pipeline.textile +416 -0
  16. data/guides/source/association_basics.textile +2 -4
  17. data/guides/source/caching_with_rails.textile +7 -6
  18. data/guides/source/command_line.textile +78 -116
  19. data/guides/source/configuring.textile +34 -17
  20. data/guides/source/contribute.textile +1 -1
  21. data/guides/source/contributing_to_ruby_on_rails.textile +3 -3
  22. data/guides/source/debugging_rails_applications.textile +2 -2
  23. data/guides/source/form_helpers.textile +40 -51
  24. data/guides/source/getting_started.textile +641 -197
  25. data/guides/source/initialization.textile +4 -4
  26. data/guides/source/layouts_and_rendering.textile +2 -2
  27. data/guides/source/migrations.textile +114 -32
  28. data/guides/source/nested_model_forms.textile +6 -6
  29. data/guides/source/performance_testing.textile +6 -6
  30. data/guides/source/plugins.textile +23 -22
  31. data/guides/source/rails_application_templates.textile +8 -14
  32. data/guides/source/routing.textile +57 -51
  33. data/guides/source/ruby_on_rails_guides_guidelines.textile +3 -3
  34. data/guides/source/security.textile +10 -10
  35. data/guides/source/testing.textile +1 -1
  36. data/lib/rails.rb +27 -1
  37. data/lib/rails/all.rb +1 -0
  38. data/lib/rails/application.rb +4 -10
  39. data/lib/rails/application/configuration.rb +3 -12
  40. data/lib/rails/application/railties.rb +1 -1
  41. data/lib/rails/engine.rb +53 -42
  42. data/lib/rails/generators.rb +1 -1
  43. data/lib/rails/generators/app_base.rb +36 -15
  44. data/lib/rails/generators/generated_attribute.rb +1 -1
  45. data/lib/rails/generators/js/assets/assets_generator.rb +13 -0
  46. data/lib/rails/generators/js/assets/templates/javascript.js +2 -0
  47. data/lib/rails/generators/rails/app/app_generator.rb +3 -1
  48. data/lib/rails/generators/rails/app/templates/Gemfile +11 -7
  49. data/lib/rails/generators/rails/app/templates/config/application.rb +7 -3
  50. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +62 -0
  51. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +3 -3
  52. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +3 -12
  53. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +3 -3
  54. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +0 -3
  55. data/lib/rails/generators/rails/assets/assets_generator.rb +2 -9
  56. data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +12 -10
  57. data/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +5 -2
  58. data/lib/rails/generators/rails/plugin_new/templates/Gemfile +6 -3
  59. data/lib/rails/generators/rails/plugin_new/templates/Rakefile +5 -1
  60. data/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/application.html.erb.tt +14 -0
  61. data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +5 -3
  62. data/lib/rails/info.rb +4 -0
  63. data/lib/rails/paths.rb +5 -5
  64. data/lib/rails/railtie.rb +4 -4
  65. data/lib/rails/tasks.rb +0 -1
  66. data/lib/rails/tasks/documentation.rake +3 -3
  67. data/lib/rails/tasks/engine.rake +2 -0
  68. data/lib/rails/tasks/framework.rake +3 -3
  69. data/lib/rails/tasks/tmp.rake +1 -1
  70. data/lib/rails/test_unit/testing.rake +2 -2
  71. data/lib/rails/version.rb +1 -1
  72. metadata +19 -33
  73. data/lib/rails/generators/rails/assets/templates/javascript.js.coffee +0 -3
  74. data/lib/rails/tasks/assets.rake +0 -21
@@ -443,7 +443,7 @@ class CreateAssemblyPartJoinTable < ActiveRecord::Migration
443
443
  end
444
444
  </ruby>
445
445
 
446
- We pass +:id => false+ to +create_table+ because that table does not represent a model. That's required for the association to work properly. If you observe any strange behaviour in a +has_and_belongs_to_many+ association like mangled models IDs, or exceptions about conflicting IDs chances are you forgot that bit.
446
+ We pass +:id => false+ to +create_table+ because that table does not represent a model. That's required for the association to work properly. If you observe any strange behavior in a +has_and_belongs_to_many+ association like mangled models IDs, or exceptions about conflicting IDs chances are you forgot that bit.
447
447
 
448
448
  h4. Controlling Association Scope
449
449
 
@@ -1120,11 +1120,9 @@ h6(#has_many-collection-find). <tt><em>collection</em>.find(...)</tt>
1120
1120
  The <tt><em>collection</em>.find</tt> method finds objects within the collection. It uses the same syntax and options as +ActiveRecord::Base.find+.
1121
1121
 
1122
1122
  <ruby>
1123
- @open_orders = @customer.orders.all(:conditions => "open = 1")
1123
+ @open_orders = @customer.orders.where(:open => 1)
1124
1124
  </ruby>
1125
1125
 
1126
- NOTE: Starting Rails 3, supplying options to +ActiveRecord::Base.find+ method is discouraged. Use <tt><em>collection</em>.where</tt> instead when you need to pass conditions.
1127
-
1128
1126
  h6(#has_many-collection-where). <tt><em>collection</em>.where(...)</tt>
1129
1127
 
1130
1128
  The <tt><em>collection</em>.where</tt> method finds objects within the collection based on the conditions supplied but the objects are loaded lazily meaning that the database is queried only when the object(s) are accessed.
@@ -15,7 +15,7 @@ h3. Basic Caching
15
15
 
16
16
  This is an introduction to the three types of caching techniques that Rails provides by default without the use of any third party plugins.
17
17
 
18
- To start playing with testing you'll want to ensure that +config.action_controller.perform_caching+ is set to +true+ if you're running in development mode. This flag is normally set in the corresponding +config/environments/*.rb+ and caching is disabled by default for development and test, and enabled for production.
18
+ To start playing with caching you'll want to ensure that +config.action_controller.perform_caching+ is set to +true+, if you're running in development mode. This flag is normally set in the corresponding +config/environments/*.rb+ and caching is disabled by default for development and test, and enabled for production.
19
19
 
20
20
  <ruby>
21
21
  config.action_controller.perform_caching = true
@@ -23,9 +23,9 @@ config.action_controller.perform_caching = true
23
23
 
24
24
  h4. Page Caching
25
25
 
26
- Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the webserver (i.e. apache or nginx), without ever having to go through the Rails stack at all. Obviously, this is super-fast. Unfortunately, it can't be applied to every situation (such as pages that need authentication) and since the webserver is literally just serving a file from the filesystem, cache expiration is an issue that needs to be dealt with.
26
+ Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the webserver (i.e. Apache or nginx), without ever having to go through the Rails stack at all. Obviously, this is super-fast. Unfortunately, it can't be applied to every situation (such as pages that need authentication) and since the webserver is literally just serving a file from the filesystem, cache expiration is an issue that needs to be dealt with.
27
27
 
28
- So, how do you enable this super-fast cache behavior? Simple, let's say you have a controller called +ProductsController+ and an +index+ action that lists all the products
28
+ To enable page caching, you need to use the +caches_page+ method.
29
29
 
30
30
  <ruby>
31
31
  class ProductsController < ActionController
@@ -35,11 +35,10 @@ class ProductsController < ActionController
35
35
  def index
36
36
  @products = Products.all
37
37
  end
38
-
39
38
  end
40
39
  </ruby>
41
40
 
42
- The first time anyone requests +/products+, Rails will generate a file called +products.html+ and the webserver will then look for that file before it passes the next request for +/products+ to your Rails application.
41
+ Let's say you have a controller called +ProductsController+ and an +index+ action that lists all the products. The first time anyone requests +/products+, Rails will generate a file called +products.html+ and the webserver will then look for that file before it passes the next request for +/products+ to your Rails application.
43
42
 
44
43
  By default, the page cache directory is set to +Rails.public_path+ (which is usually set to the +public+ folder) and this can be configured by changing the configuration setting +config.action_controller.page_cache_directory+. Changing the default from +public+ helps avoid naming conflicts, since you may want to put other static html in +public+, but changing this will require web server reconfiguration to let the web server know where to serve the cached files from.
45
44
 
@@ -104,7 +103,7 @@ INFO: Action caching runs in an after filter. Thus, invalid requests won't gener
104
103
 
105
104
  h4. Fragment Caching
106
105
 
107
- Life would be perfect if we could get away with caching the entire contents of a page or action and serving it out to the world. Unfortunately, dynamic web applications usually build pages with a variety of components not all of which have the same caching characteristics. In order to address such a dynamically created page where different parts of the page need to be cached and expired differently Rails provides a mechanism called Fragment Caching.
106
+ Life would be perfect if we could get away with caching the entire contents of a page or action and serving it out to the world. Unfortunately, dynamic web applications usually build pages with a variety of components not all of which have the same caching characteristics. In order to address such a dynamically created page where different parts of the page need to be cached and expired differently, Rails provides a mechanism called Fragment Caching.
108
107
 
109
108
  Fragment Caching allows a fragment of view logic to be wrapped in a cache block and served out of the cache store when the next request comes in.
110
109
 
@@ -382,6 +381,7 @@ class ProductsController < ApplicationController
382
381
  # anything. The default render checks for this using the parameters
383
382
  # used in the previous call to stale? and will automatically send a
384
383
  # :not_modified. So that's it, you're done.
384
+ end
385
385
  end
386
386
  </ruby>
387
387
 
@@ -415,3 +415,4 @@ h3. Changelog
415
415
  * December 27, 2008: Typo fixes
416
416
  * November 23, 2008: Incremental updates with various suggested changes and formatting cleanup
417
417
  * September 15, 2008: Initial version by Aditya Chadha
418
+
@@ -5,7 +5,7 @@ Rails comes with every command line tool you'll need to
5
5
  * Create a Rails application
6
6
  * Generate models, controllers, database migrations, and unit tests
7
7
  * Start a development server
8
- * Mess with objects through an interactive shell
8
+ * Experiment with objects through an interactive shell
9
9
  * Profile and benchmark your new creation
10
10
 
11
11
  endprologue.
@@ -51,15 +51,13 @@ $ rails new commandsapp
51
51
 
52
52
  Rails will set you up with what seems like a huge amount of stuff for such a tiny command! You've got the entire Rails directory structure now with all the code you need to run our simple application right out of the box.
53
53
 
54
- INFO: This output will seem very familiar when we get to the +generate+ command. Creepy foreshadowing!
55
-
56
54
  h4. +rails server+
57
55
 
58
- The +rails server+ command launches a small web server named WEBrick which comes bundled with Ruby. You'll use this any time you want to view your work through a web browser.
56
+ The +rails server+ command launches a small web server named WEBrick which comes bundled with Ruby. You'll use this any time you want to access your application through a web browser.
59
57
 
60
- INFO: WEBrick isn't your only option for serving Rails. We'll get to that in a later section.
58
+ INFO: WEBrick isn't your only option for serving Rails. We'll get to that "later":#different-servers.
61
59
 
62
- Without any prodding of any kind, +rails server+ will run our new shiny Rails app:
60
+ With no further work, +rails server+ will run our new shiny Rails app:
63
61
 
64
62
  <shell>
65
63
  $ cd commandsapp
@@ -77,13 +75,21 @@ With just three commands we whipped up a Rails server listening on port 3000. Go
77
75
 
78
76
  You can also use the alias "s" to start the server: <tt>rails s</tt>.
79
77
 
78
+ The server can be run on a different port using the +-p+ option. The default development environment can be changed using +-e+.
79
+
80
+ <shell>
81
+ $ rails server -e production -p 4000
82
+ </shell>
83
+
80
84
  h4. +rails generate+
81
85
 
82
- The +rails generate+ command uses templates to create a whole lot of things. You can always find out what's available by running +rails generate+ by itself. Let's do that:
86
+ The +rails generate+ command uses templates to create a whole lot of things. Running +rails generate+ by itself gives a list of available generators:
87
+
88
+ You can also use the alias "g" to invoke the generator command: <tt>rails g</tt>.
83
89
 
84
90
  <shell>
85
91
  $ rails generate
86
- Usage: rails generate generator [args] [options]
92
+ Usage: rails generate GENERATOR [args] [options]
87
93
 
88
94
  ...
89
95
  ...
@@ -99,7 +105,7 @@ Rails:
99
105
 
100
106
  NOTE: You can install more generators through generator gems, portions of plugins you'll undoubtedly install, and you can even create your own!
101
107
 
102
- Using generators will save you a large amount of time by writing *boilerplate code*, code that is necessary for the app to work, but not necessary for you to spend time writing. That's what we have computers for.
108
+ Using generators will save you a large amount of time by writing *boilerplate code*, code that is necessary for the app to work.
103
109
 
104
110
  Let's make our own controller with the controller generator. But what command should we use? Let's ask the generator:
105
111
 
@@ -148,7 +154,8 @@ $ rails generate controller Greetings hello
148
154
  create test/unit/helpers/greetings_helper_test.rb
149
155
  invoke assets
150
156
  create app/assets/javascripts/greetings.js
151
- create app/assets/stylesheets/greetings.css
157
+ invoke css
158
+ create app/assets/stylesheets/greetings.css
152
159
 
153
160
  </shell>
154
161
 
@@ -171,7 +178,7 @@ Then the view, to display our message (in +app/views/greetings/hello.html.erb+):
171
178
  <p><%= @message %></p>
172
179
  </html>
173
180
 
174
- Deal. Go check it out in your browser. Fire up your server using +rails server+.
181
+ Fire up your server using +rails server+.
175
182
 
176
183
  <shell>
177
184
  $ rails server
@@ -184,7 +191,7 @@ The URL will be "http://localhost:3000/greetings/hello":http://localhost:3000/gr
184
191
 
185
192
  INFO: With a normal, plain-old Rails application, your URLs will generally follow the pattern of http://(host)/(controller)/(action), and a URL like http://(host)/(controller) will hit the *index* action of that controller.
186
193
 
187
- Rails comes with a generator for data models too:
194
+ Rails comes with a generator for data models too.
188
195
 
189
196
  <shell>
190
197
  $ rails generate model
@@ -288,11 +295,7 @@ You can also use the alias "db" to invoke the dbconsole: <tt>rails db</tt>.
288
295
 
289
296
  h4. +rails plugin+
290
297
 
291
- The +rails plugin+ command simplifies plugin management; think a miniature version of the Gem utility. Let's walk through installing a plugin. You can call the sub-command +discover+, which sifts through repositories looking for plugins, or call +source+ to add a specific repository of plugins, or you can specify the plugin location directly.
292
-
293
- Let's say you're creating a website for a client who wants a small accounting system. Every event having to do with money must be logged, and must never be deleted. Wouldn't it be great if we could override the behavior of a model to never actually take its record out of the database, but instead, just set a field?
294
-
295
- There is such a thing! The plugin we're installing is called +acts_as_paranoid+, and it lets models implement a +deleted_at+ column that gets set when you call destroy. Later, when calling find, the plugin will tack on a database check to filter out "deleted" things.
298
+ The +rails plugin+ command simplifies plugin management. Plugins can be installed by name or their repository URLs. You need to have Git installed if you want to install a plugin from a Git repo. The same holds for Subversion too.
296
299
 
297
300
  <shell>
298
301
  $ rails plugin install https://github.com/technoweenie/acts_as_paranoid.git
@@ -310,6 +313,14 @@ h4. +rails runner+
310
313
  $ rails runner "Model.long_running_method"
311
314
  </shell>
312
315
 
316
+ You can also use the alias "r" to invoke the runner: <tt>rails r</tt>.
317
+
318
+ You can specify the environment in which the +runner+ command should operate using the +-e+ switch.
319
+
320
+ <shell>
321
+ $ rails runner -e staging "Model.long_running_method"
322
+ </shell>
323
+
313
324
  h4. +rails destroy+
314
325
 
315
326
  Think of +destroy+ as the opposite of +generate+. It'll figure out what generate did, and undo it.
@@ -388,13 +399,56 @@ h4. +db+
388
399
 
389
400
  The most common tasks of the +db:+ Rake namespace are +migrate+ and +create+, and it will pay off to try out all of the migration rake tasks (+up+, +down+, +redo+, +reset+). +rake db:version+ is useful when troubleshooting, telling you the current version of the database.
390
401
 
402
+ More information about migrations can be found in the "Migrations":migrations.html guide.
403
+
391
404
  h4. +doc+
392
405
 
393
- If you want to strip out or rebuild any of the Rails documentation (including this guide!), the +doc:+ namespace has the tools. Stripping documentation is mainly useful for slimming your codebase, like if you're writing a Rails application for an embedded platform.
406
+ The +doc:+ namespace has the tools to generate documentation for your app, API documentation, guides. Documentation can also be stripped which is mainly useful for slimming your codebase, like if you're writing a Rails application for an embedded platform.
407
+
408
+ * +rake doc:app+ generates documentation for your application in +doc/app+.
409
+ * +rake doc:guides+ generates Rails guides in +doc/guides+.
410
+ * +rake doc:rails+ generates API documentation for Rails in +doc/api+.
411
+ * +rake doc:plugins+ generates API documentation for all the plugins installed in the application in +doc/plugins+.
412
+ * +rake doc:clobber_plugins+ removes the generated documentation for all plugins.
394
413
 
395
414
  h4. +notes+
396
415
 
397
- These tasks will search through your code for commented lines beginning with "FIXME", "OPTIMIZE", "TODO", or any custom annotation (like XXX) and show you them.
416
+ +rake notes+ will search through your code for comments beginning with FIXME, OPTIMIZE or TODO. The search is only done in files with extension +.builder+, +.rb+, +.rxml+, +.rhtml+ and +.erb+ for both default and custom annotations.
417
+
418
+ <shell>
419
+ $ rake notes
420
+ (in /home/foobar/commandsapp)
421
+ app/controllers/admin/users_controller.rb:
422
+ * [ 20] [TODO] any other way to do this?
423
+ * [132] [FIXME] high priority for next deploy
424
+
425
+ app/model/school.rb:
426
+ * [ 13] [OPTIMIZE] refactor this code to make it faster
427
+ * [ 17] [FIXME]
428
+ </shell>
429
+
430
+ If you are looking for a specific annotation, say FIXME, you can use +rake notes:fixme+. Note that you have to lower case the annotation's name.
431
+
432
+ <shell>
433
+ $ rake notes:fixme
434
+ (in /home/foobar/commandsapp)
435
+ app/controllers/admin/users_controller.rb:
436
+ * [132] high priority for next deploy
437
+
438
+ app/model/school.rb:
439
+ * [ 17]
440
+ </shell>
441
+
442
+ You can also use custom annotations in your code and list them using +rake notes:custom+ by specifying the annotation using an environment variable +ANNOTATION+.
443
+
444
+ <shell>
445
+ $ rake notes:custom ANNOTATION=BUG
446
+ (in /home/foobar/commandsapp)
447
+ app/model/post.rb:
448
+ * [ 23] Have to fix this one before pushing!
449
+ </shell>
450
+
451
+ NOTE. When using specific annotations and custom annotations, the annotation name (FIXME, BUG etc) is not displayed in the output lines.
398
452
 
399
453
  h4. +routes+
400
454
 
@@ -478,11 +532,13 @@ development:
478
532
  ...
479
533
  </shell>
480
534
 
481
- It also generated some lines in our database.yml configuration corresponding to our choice of PostgreSQL for database. The only catch with using the SCM options is that you have to make your application's directory first, then initialize your SCM, then you can run the +rails new+ command to generate the basis of your app.
535
+ It also generated some lines in our database.yml configuration corresponding to our choice of PostgreSQL for database.
536
+
537
+ NOTE. The only catch with using the SCM options is that you have to make your application's directory first, then initialize your SCM, then you can run the +rails new+ command to generate the basis of your app.
482
538
 
483
- h4. +server+ with Different Backends
539
+ h4(#different-servers). +server+ with Different Backends
484
540
 
485
- Many people have created a large number different web servers in Ruby, and many of them can be used to run Rails. Since version 2.3, Rails uses Rack to serve its webpages, which means that any webserver that implements a Rack handler can be used. This includes WEBrick, Mongrel, Thin, and Phusion Passenger (to name a few!).
541
+ Many people have created a large number of different web servers in Ruby, and many of them can be used to run Rails. Since version 2.3, Rails uses Rack to serve its webpages, which means that any webserver that implements a Rack handler can be used. This includes WEBrick, Mongrel, Thin, and Phusion Passenger (to name a few!).
486
542
 
487
543
  NOTE: For more details on the Rack integration, see "Rails on Rack":rails_on_rack.html.
488
544
 
@@ -504,97 +560,3 @@ $ rails server mongrel
504
560
  => Rails 3.1.0 application starting on http://0.0.0.0:3000
505
561
  ...
506
562
  </shell>
507
-
508
- h4. The Rails Generation: Generators
509
-
510
- INFO: For a good rundown on generators, see "Understanding Generators":http://wiki.rubyonrails.org/rails/pages/UnderstandingGenerators. A lot of its material is presented here.
511
-
512
- Generators are code that generates code. Let's experiment by building one. Our generator will generate a text file.
513
-
514
- The Rails generator by default looks in these places for available generators, where Rails.root is the root of your Rails application, like /home/foobar/commandsapp:
515
-
516
- * Rails.root/lib/generators
517
- * Rails.root/vendor/generators
518
- * Inside any plugin with a directory like "generators" or "rails_generators"
519
- * ~/.rails/generators
520
- * Inside any Gem you have installed with a name ending in "_generator"
521
- * Inside any Gem installed with a "rails_generators" path, and a file ending in "_generator.rb"
522
- * Finally, the builtin Rails generators (controller, model, mailer, etc.)
523
-
524
- Let's try the fourth option (in our home directory), which will be easy to clean up later:
525
-
526
- <shell>
527
- $ mkdir -p ~/.rails/generators/tutorial_test/templates
528
- $ touch ~/.rails/generators/tutorial_test/templates/tutorial.erb
529
- $ touch ~/.rails/generators/tutorial_test/tutorial_test_generator.rb
530
- </shell>
531
-
532
- We'll fill +tutorial_test_generator.rb+ out with:
533
-
534
- <ruby>
535
- class TutorialTestGenerator < Rails::Generator::Base
536
- def initialize(*runtime_args)
537
- super(*runtime_args)
538
- @tut_args = runtime_args
539
- end
540
-
541
- def manifest
542
- record do |m|
543
- m.directory "public"
544
- m.template "tutorial.erb", File.join("public", "tutorial.txt"),
545
- :assigns => { :args => @tut_args }
546
- end
547
- end
548
- end
549
- </ruby>
550
-
551
- We take whatever args are supplied, save them to an instance variable, and literally copying from the Rails source, implement a +manifest+ method, which calls +record+ with a block, and we:
552
-
553
- * Check there's a *public* directory. You bet there is.
554
- * Run the ERB template called "tutorial.erb".
555
- * Save it into "Rails.root/public/tutorial.txt".
556
- * Pass in the arguments we saved through the +:assigns+ parameter.
557
-
558
- Next we'll build the template:
559
-
560
- <shell>
561
- $ cat ~/.rails/generators/tutorial_test/templates/tutorial.erb
562
- I'm a template!
563
-
564
- I got assigned some args:
565
- <%= require 'pp'; PP.pp(args, "") %>
566
- </shell>
567
-
568
- Then we'll make sure it got included in the list of available generators:
569
-
570
- <shell>
571
- $ rails generate
572
- ...
573
- ...
574
- Installed Generators
575
- User: tutorial_test
576
- </shell>
577
-
578
- SWEET! Now let's generate some text, yeah!
579
-
580
- <shell>
581
- $ rails generate tutorial_test arg1 arg2 arg3
582
- exists public
583
- create public/tutorial.txt
584
- </shell>
585
-
586
- And the result:
587
-
588
- <shell>
589
- $ cat public/tutorial.txt
590
- I'm a template!
591
-
592
- I got assigned some args:
593
- [["arg1", "arg2", "arg3"],
594
- {:collision=>:ask,
595
- :quiet=>false,
596
- :generator=>"tutorial_test",
597
- :command=>:create}]
598
- </shell>
599
-
600
- Tada!
@@ -98,7 +98,7 @@ NOTE. The +config.asset_path+ configuration is ignored if the asset pipeline is
98
98
 
99
99
  * +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+.
100
100
 
101
- * +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.
101
+ * +config.serve_static_assets+ configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. Nginx or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won´t be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.
102
102
 
103
103
  * +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+ which is the default, +:mem_cache_store+, and +:disabled+. The last one tells Rails not to deal with sessions. Custom session stores can also be specified:
104
104
 
@@ -116,8 +116,25 @@ WARNING: Threadsafe operation is incompatible with the normal workings of develo
116
116
 
117
117
  * +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.
118
118
 
119
+ h4. Configuring Assets
120
+
121
+ Rails 3.1, by default, is set up to use the +sprockets+ gem to manage assets within an application. This gem concatenates and compresses assets in order to make serving them much less painful.
122
+
119
123
  * +config.assets.enabled+ a flag that controls whether the asset pipeline is enabled. It is explicitly initialized in +config/application.rb+.
120
124
 
125
+ * +config.assets.compress+ a flag that enables the compression of compiled assets. It is explicitly set to true in +config/production.rb+.
126
+
127
+ * +config.assets.css_compressor+ defines the CSS compressor to use. Only supported value at the moment is +:yui+, which uses the +yui-compressor+ gem.
128
+
129
+ * +config.assets.js_compressor+ defines the JavaScript compressor to use. Possible values are +:closure+, +:uglifier+ and +:yui+ which require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively.
130
+
131
+ * +config.assets.paths+ contains the paths which are used to look for assets. Appending paths to this configuration option will cause those paths to be used in the search for assets.
132
+
133
+ * +config.assets.precompile+ allows you to specify additional assets (other than +application.css+ and +application.js+) which are to be precompiled when +rake assets:precompile+ is run.
134
+
135
+ * +config.assets.prefix+ defines the prefix where assets are served from. Defaults to +/assets+.
136
+
137
+
121
138
  h4. Configuring Generators
122
139
 
123
140
  Rails 3 allows you to alter what generators are used with the +config.generators+ method. This method takes a block:
@@ -220,21 +237,21 @@ h4. Configuring Active Record
220
237
 
221
238
  * +config.active_record.table_name_suffix+ lets you set a global string to be appended to table names. If you set this to +_northwest+, then the Customer class will look for +customers_northwest+ as its table. The default is an empty string.
222
239
 
223
- * +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 Customer class will use the +customer+ table.
240
+ * +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 Customer class will use the +customer+ table.
224
241
 
225
242
  * +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 Active Record defaults to +:local+ when used outside of Rails.
226
243
 
227
244
  * +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.
228
245
 
229
- * +config.active_record.timestamped_migrations+ controls whether migrations are numbered with serial integers or with timestamps. The default is +true+, to use timestamps, which are preferred if there are multiple developers working on the same application.
246
+ * +config.active_record.timestamped_migrations+ controls whether migrations are numbered with serial integers or with timestamps. The default is true, to use timestamps, which are preferred if there are multiple developers working on the same application.
230
247
 
231
- * +config.active_record.lock_optimistically+ controls whether Active Record will use optimistic locking. By default this is +true+.
248
+ * +config.active_record.lock_optimistically+ controls whether Active Record will use optimistic locking and is true by default.
232
249
 
233
250
  * +config.active_record.whitelist_attributes+ will create an empty whitelist of attributes available for mass-assignment security for all models in your app.
234
251
 
235
252
  The MySQL adapter adds one additional configuration option:
236
253
 
237
- * +ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans+ controls whether Active Record will consider all +tinyint(1)+ columns in a MySQL database to be booleans. By default this is +true+.
254
+ * +ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans+ controls whether Active Record will consider all +tinyint(1)+ columns in a MySQL database to be booleans and is true by default.
238
255
 
239
256
  The schema dumper adds one additional configuration option:
240
257
 
@@ -260,7 +277,7 @@ h4. Configuring Action Controller
260
277
 
261
278
  * +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.
262
279
 
263
- * +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.
280
+ * +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.
264
281
 
265
282
  * +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']+.
266
283
 
@@ -330,7 +347,7 @@ And can reference in the view with the following code:
330
347
  <%= stylesheet_link_tag :special %>
331
348
  </ruby>
332
349
 
333
- * +ActionView::Helpers::AssetTagHelper::AssetPaths.cache_asset_ids+ With the cache enabled, the asset tag helper methods will make fewer expensive file system calls (the default implementation checks the file system timestamp). However this prevents you from modifying any asset files while the server is running.
350
+ * +config.action_view.cache_asset_ids+ With the cache enabled, the asset tag helper methods will make fewer expensive file system calls (the default implementation checks the file system timestamp). However this prevents you from modifying any asset files while the server is running.
334
351
 
335
352
  h4. Configuring Action Mailer
336
353
 
@@ -350,11 +367,11 @@ There are a number of settings available on +config.action_mailer+:
350
367
  ** +:location+ - The location of the sendmail executable. Defaults to +/usr/sbin/sendmail+.
351
368
  ** +:arguments+ - The command line arguments. Defaults to +-i -t+.
352
369
 
353
- * +config.action_mailer.raise_delivery_errors+ specifies whether to raise an error if email delivery cannot be completed. It defaults to +true+.
370
+ * +config.action_mailer.raise_delivery_errors+ specifies whether to raise an error if email delivery cannot be completed. It defaults to true.
354
371
 
355
372
  * +config.action_mailer.delivery_method+ defines the delivery method. The allowed values are +:smtp+ (default), +:sendmail+, and +:test+.
356
373
 
357
- * +config.action_mailer.perform_deliveries+ specifies whether mail will actually be delivered. By default this is +true+; it can be convenient to set it to +false+ for testing.
374
+ * +config.action_mailer.perform_deliveries+ specifies whether mail will actually be delivered and is true by default. It can be convenient to set it to false for testing.
358
375
 
359
376
  * +config.action_mailer.default+ configures Action Mailer defaults. These default to:
360
377
  <ruby>
@@ -366,12 +383,12 @@ There are a number of settings available on +config.action_mailer+:
366
383
 
367
384
  * +config.action_mailer.observers+ registers observers which will be notified when mail is delivered.
368
385
  <ruby>
369
- config.active_record.observers = ["MailObserver"]
386
+ config.action_mailer.observers = ["MailObserver"]
370
387
  </ruby>
371
388
 
372
389
  * +config.action_mailer.interceptors+ registers interceptors which will be called before mail is sent.
373
390
  <ruby>
374
- config.active_record.interceptors = ["MailInterceptor"]
391
+ config.action_mailer.interceptors = ["MailInterceptor"]
375
392
  </ruby>
376
393
 
377
394
  h4. Configuring Active Resource
@@ -478,13 +495,13 @@ Serves as a placeholder so that +:load_environment_config+ can be defined to run
478
495
 
479
496
  *+set_clear_dependencies_hook+* Provides a hook for +active_record.set_dispatch_hooks+ to use, which will run before this initializer. This initializer -- which runs only if +cache_classes+ is set to +false+ -- uses +ActionDispatch::Callbacks.after+ to remove the constants which have been referenced during the request from the object space so that they will be reloaded during the following request.
480
497
 
481
- *+initialize_dependency_mechanism+* If +config.cache_classes+ is set to +true+, configures +ActiveSupport::Dependencies.mechanism+ to +require+ dependencies rather than +load+ them.
498
+ *+initialize_dependency_mechanism+* If +config.cache_classes+ is true, configures +ActiveSupport::Dependencies.mechanism+ to +require+ dependencies rather than +load+ them.
482
499
 
483
500
  *+bootstrap_hook+* Runs all configured +before_initialize+ blocks.
484
501
 
485
502
  *+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.
486
503
 
487
- *+active_support.initialize_whiny_nils+* Requires +active_support/whiny_nil+ if +config.whiny_nils+ is set to +true+. This file will output errors such as:
504
+ *+active_support.initialize_whiny_nils+* Requires +active_support/whiny_nil+ if +config.whiny_nils+ is true. This file will output errors such as:
488
505
 
489
506
  <plain>
490
507
  Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
@@ -506,7 +523,7 @@ The error occurred while evaluating nil.each
506
523
 
507
524
  *+action_view.cache_asset_ids+* Sets +ActionView::Helpers::AssetTagHelper::AssetPaths.cache_asset_ids+ to +false+ when Active Support loads, but only if +config.cache_classes+ is too.
508
525
 
509
- *+action_view.javascript_expansions+* Registers the expansions set up by +config.action_view.javascript_expansions+ and +config.action_view.stylesheet_expansions+ to be recognised by Action View and therefore usable in the views.
526
+ *+action_view.javascript_expansions+* Registers the expansions set up by +config.action_view.javascript_expansions+ and +config.action_view.stylesheet_expansions+ to be recognized by Action View and therefore usable in the views.
510
527
 
511
528
  *+action_view.set_configs+* Sets up Action View by using the settings in +config.action_view+ by +send+'ing the method names as setters to +ActionView::Base+ and passing the values through.
512
529
 
@@ -568,13 +585,13 @@ The error occurred while evaluating nil.each
568
585
 
569
586
  *+build_middleware_stack+* Builds the middleware stack for the application, returning an object which has a +call+ method which takes a Rack environment object for the request.
570
587
 
571
- *+eager_load!+* If +config.cache_classes+ is +true+, runs the +config.before_eager_load+ hooks and then calls +eager_load!+ which will load all the Ruby files from +config.eager_load_paths+.
588
+ *+eager_load!+* If +config.cache_classes+ is true, runs the +config.before_eager_load+ hooks and then calls +eager_load!+ which will load all the Ruby files from +config.eager_load_paths+.
572
589
 
573
590
  *+finisher_hook+* Provides a hook for after the initialization of process of the application is complete, as well as running all the +config.after_initialize+ blocks for the application, railties and engines.
574
591
 
575
592
  *+set_routes_reloader+* Configures Action Dispatch to reload the routes file using +ActionDispatch::Callbacks.to_prepare+.
576
593
 
577
- *+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+.
594
+ *+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.
578
595
 
579
596
  h3. Changelog
580
597
 
@@ -582,4 +599,4 @@ h3. Changelog
582
599
  * November 26, 2010: Removed all config settings not available in Rails 3 ("Ryan Bigg":http://ryanbigg.com)
583
600
  * August 13, 2009: Updated with config syntax and added general configuration options by "John Pignata"
584
601
  * January 3, 2009: First reasonably complete draft by "Mike Gunderloy":credits.html#mgunderloy
585
- * November 5, 2008: Rough outline by "Mike Gunderloy":credits.html#mgunderloy
602
+ * November 5, 2008: Rough outline by "Mike Gunderloy":credits.html#mgunderloy