railties 3.1.0.rc1 → 3.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/CHANGELOG +2 -0
  2. data/guides/assets/images/radar.png +0 -0
  3. data/guides/assets/images/vijaydev.jpg +0 -0
  4. data/guides/rails_guides/helpers.rb +1 -1
  5. data/guides/source/action_view_overview.textile +6 -103
  6. data/guides/source/active_record_basics.textile +2 -2
  7. data/guides/source/active_record_querying.textile +32 -4
  8. data/guides/source/active_record_validations_callbacks.textile +5 -3
  9. data/guides/source/active_support_core_extensions.textile +4 -4
  10. data/guides/source/api_documentation_guidelines.textile +2 -2
  11. data/guides/source/caching_with_rails.textile +5 -5
  12. data/guides/source/command_line.textile +78 -71
  13. data/guides/source/configuring.textile +90 -74
  14. data/guides/source/contribute.textile +2 -2
  15. data/guides/source/contributing_to_ruby_on_rails.textile +3 -3
  16. data/guides/source/credits.html.erb +16 -8
  17. data/guides/source/generators.textile +3 -3
  18. data/guides/source/getting_started.textile +1 -1
  19. data/guides/source/i18n.textile +1 -1
  20. data/guides/source/initialization.textile +311 -310
  21. data/guides/source/migrations.textile +4 -4
  22. data/guides/source/rails_on_rack.textile +6 -6
  23. data/guides/source/routing.textile +1 -1
  24. data/guides/source/testing.textile +2 -2
  25. data/lib/rails/application.rb +17 -12
  26. data/lib/rails/commands.rb +1 -1
  27. data/lib/rails/commands/benchmarker.rb +3 -3
  28. data/lib/rails/commands/console.rb +2 -1
  29. data/lib/rails/commands/profiler.rb +3 -3
  30. data/lib/rails/commands/server.rb +2 -1
  31. data/lib/rails/configuration.rb +6 -0
  32. data/lib/rails/engine.rb +1 -1
  33. data/lib/rails/generators.rb +8 -2
  34. data/lib/rails/generators/css/assets/assets_generator.rb +13 -0
  35. data/lib/rails/generators/{rails/assets/templates/stylesheet.css.scss → css/assets/templates/stylesheet.css} +1 -2
  36. data/lib/rails/generators/css/scaffold/scaffold_generator.rb +16 -0
  37. data/lib/rails/generators/rails/app/app_generator.rb +1 -1
  38. data/lib/rails/generators/rails/app/templates/Gemfile +2 -2
  39. data/lib/rails/generators/rails/app/templates/config/application.rb +0 -11
  40. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +3 -0
  41. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +4 -2
  42. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +2 -2
  43. data/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb +1 -1
  44. data/lib/rails/generators/rails/assets/USAGE +1 -1
  45. data/lib/rails/generators/rails/assets/assets_generator.rb +2 -9
  46. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +3 -3
  47. data/lib/rails/generators/rails/plugin_new/templates/Rakefile +8 -3
  48. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -11
  49. data/lib/rails/generators/test_unit/performance/templates/performance_test.rb +1 -1
  50. data/lib/rails/railtie.rb +7 -7
  51. data/lib/rails/railtie/configurable.rb +2 -0
  52. data/lib/rails/tasks/assets.rake +12 -1
  53. data/lib/rails/tasks/documentation.rake +8 -2
  54. data/lib/rails/tasks/misc.rake +1 -1
  55. data/lib/rails/version.rb +1 -1
  56. metadata +56 -9
  57. data/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss +0 -58
data/CHANGELOG CHANGED
@@ -1,5 +1,7 @@
1
1
  *Rails 3.1.0 (unreleased)*
2
2
 
3
+ * The new rake task assets:clean removes precompiled assets. [fxn]
4
+
3
5
  * Application and plugin generation run bundle install unless --skip-gemfile or --skip-bundle. [fxn]
4
6
 
5
7
  * Fixed database tasks for jdbc* adapters #jruby
@@ -15,7 +15,7 @@ module RailsGuides
15
15
  def author(name, nick, image = 'credits_pic_blank.gif', &block)
16
16
  image = "images/#{image}"
17
17
 
18
- result = content_tag(:img, nil, :src => image, :class => 'left pic', :alt => name)
18
+ result = content_tag(:img, nil, :src => image, :class => 'left pic', :alt => name, :width => 91, :height => 91)
19
19
  result << content_tag(:h3, name)
20
20
  result << content_tag(:p, capture(&block))
21
21
  content_tag(:div, result, :class => 'clearfix', :id => nick)
@@ -929,7 +929,7 @@ Creates a scope around a specific model object like form_for, but doesn‘t crea
929
929
 
930
930
  h5. file_field
931
931
 
932
- Returns an file upload input tag tailored for accessing a specified attribute.
932
+ Returns a file upload input tag tailored for accessing a specified attribute.
933
933
 
934
934
  <ruby>
935
935
  file_field(:user, :avatar)
@@ -1037,7 +1037,7 @@ Sample usage (selecting the associated Author for an instance of Post, +@post+):
1037
1037
  collection_select(:post, :author_id, Author.all, :id, :name_with_initial, {:prompt => true})
1038
1038
  </ruby>
1039
1039
 
1040
- If @post.author_id is already 1, this would return:
1040
+ If <tt>@post.author_id</tt> is 1, this would return:
1041
1041
 
1042
1042
  <html>
1043
1043
  <select name="post[author_id]">
@@ -1080,8 +1080,6 @@ Sample usage:
1080
1080
  option_groups_from_collection_for_select(@continents, :countries, :name, :id, :name, 3)
1081
1081
  </ruby>
1082
1082
 
1083
- TODO check above textile output looks right
1084
-
1085
1083
  Possible output:
1086
1084
 
1087
1085
  <html>
@@ -1132,13 +1130,13 @@ h5. select
1132
1130
 
1133
1131
  Create a select tag and a series of contained option tags for the provided object and method.
1134
1132
 
1135
- Example with @post.person_id => 1:
1133
+ Example:
1136
1134
 
1137
1135
  <ruby>
1138
1136
  select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, { :include_blank => true })
1139
1137
  </ruby>
1140
1138
 
1141
- could become:
1139
+ If <tt>@post.person_id</tt> is 1, this would become:
1142
1140
 
1143
1141
  <html>
1144
1142
  <select name="post[person_id]">
@@ -1189,7 +1187,7 @@ h5. file_field_tag
1189
1187
 
1190
1188
  Creates a file upload field.
1191
1189
 
1192
- If you are using file uploads then you will also need to set the multipart option for the form tag:
1190
+ Prior to Rails 3.1, if you are using file uploads, then you will need to set the multipart option for the form tag. Rails 3.1+ does this automatically.
1193
1191
 
1194
1192
  <ruby>
1195
1193
  <%= form_tag { :action => "post" }, { :multipart => true } do %>
@@ -1400,102 +1398,6 @@ number_with_precision(111.2345) # => 111.235
1400
1398
  number_with_precision(111.2345, 2) # => 111.23
1401
1399
  </ruby>
1402
1400
 
1403
- h5. evaluate_remote_response
1404
-
1405
- Returns +eval(request.responseText)+ which is the JavaScript function that form_remote_tag can call in +:complete+ to evaluate a multiple update return document using +update_element_function+ calls.
1406
-
1407
- h5. form_remote_tag
1408
-
1409
- Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement. Even though it‘s using JavaScript to serialize the form elements, the form submission will work just like a regular submission as viewed by the receiving side.
1410
-
1411
- For example, this:
1412
-
1413
- <ruby>
1414
- form_remote_tag :html => { :action => url_for(:controller => "some", :action => "place") }
1415
- </ruby>
1416
-
1417
- would generate the following:
1418
-
1419
- <html>
1420
- <form action="/some/place" method="post" onsubmit="new Ajax.Request('',
1421
- {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">
1422
- </html>
1423
-
1424
- h5. link_to_remote
1425
-
1426
- Returns a link to a remote action that's called in the background using XMLHttpRequest. You can generate a link that uses AJAX in the general case, while degrading gracefully to plain link behavior in the absence of JavaScript. For example:
1427
-
1428
- <ruby>
1429
- link_to_remote "Delete this post",
1430
- { :update => "posts", :url => { :action => "destroy", :id => post.id } },
1431
- :href => url_for(:action => "destroy", :id => post.id)
1432
- </ruby>
1433
-
1434
- h5. observe_field
1435
-
1436
- Observes the field specified and calls a callback when its contents have changed.
1437
-
1438
- <ruby>
1439
- observe_field("my_field", :function => "alert('Field changed')")
1440
- </ruby>
1441
-
1442
- h5. observe_form
1443
-
1444
- Observes the form specified and calls a callback when its contents have changed. The options for observe_form are the same as the options for observe_field.
1445
-
1446
- <ruby>
1447
- observe_field("my_form", :function => "alert('Form changed')")
1448
- </ruby>
1449
-
1450
- h5. periodically_call_remote
1451
-
1452
- Periodically calls the specified url as often as specified. Usually used to update a specified div with the results of the remote call. The following example will call update every 20 seconds and update the news_block div:
1453
-
1454
- <ruby>
1455
- periodically_call_remote(:url => 'update', :frequency => '20', :update => 'news_block')
1456
- # => PeriodicalExecuter(function() {new Ajax.Updater('news_block', 'update', {asynchronous:true, evalScripts:true})}, 20)
1457
- </ruby>
1458
-
1459
- h5. remote_form_for
1460
-
1461
- Creates a form that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement and a scope around a specific resource that is used as a base for questioning about values for the fields.
1462
-
1463
- <ruby>
1464
- <%= remote_form_for(@post) do |f| %>
1465
- ...
1466
- <% end %>
1467
- </ruby>
1468
-
1469
- h5. remote_function
1470
-
1471
- Returns the JavaScript needed for a remote function. Takes the same arguments as +link_to_remote+.
1472
-
1473
- <ruby>
1474
- <select id="options" onchange="<%= remote_function(:update => "options", :url => { :action => :update_options }) %>">
1475
- <option value="0">Hello</option>
1476
- <option value="1">World</option>
1477
- </select>
1478
- # => <select id="options" onchange="new Ajax.Updater('options', '/testing/update_options', {asynchronous:true, evalScripts:true})">
1479
- </ruby>
1480
-
1481
- h5. submit_to_remote
1482
-
1483
- Returns a button input tag that will submit form using XMLHttpRequest in the background instead of a regular POST request that reloads the page.
1484
-
1485
- For example, the following:
1486
-
1487
- <ruby>
1488
- submit_to_remote 'create_btn', 'Create', :url => { :action => 'create' }
1489
- </ruby>
1490
-
1491
- would generate:
1492
-
1493
- <html>
1494
- <input name="create_btn" onclick="new Ajax.Request('/testing/create',
1495
- {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)});
1496
- return false;" type="button" value="Create" />
1497
- </html>
1498
-
1499
1401
  h3. Localized Views
1500
1402
 
1501
1403
  Action View has the ability render different templates depending on the current locale.
@@ -1520,6 +1422,7 @@ You can read more about the Rails Internationalization (I18n) API "here":i18n.ht
1520
1422
 
1521
1423
  h3. Changelog
1522
1424
 
1425
+ * May 29, 2011: Removed references to remote_* helpers - Vijay Dev
1523
1426
  * April 16, 2011: Added 'Using Action View with Rails', 'Templates' and 'Partials' sections. "Sebastian Martinez":http://wyeworks.com
1524
1427
  * September 3, 2009: Continuing work by Trevor Turk, leveraging the Action Pack docs and "What's new in Edge Rails":http://ryandaigle.com/articles/2007/8/3/what-s-new-in-edge-rails-partials-get-layouts
1525
1428
  * April 5, 2009: Starting work by Trevor Turk, leveraging Mike Gunderloy's docs
@@ -64,8 +64,8 @@ There are also some optional column names that will create additional features t
64
64
  * *created_on* - Automatically gets set to the current date when the record is first created.
65
65
  * *updated_at* - Automatically gets set to the current date and time whenever the record is updated.
66
66
  * *updated_on* - Automatically gets set to the current date whenever the record is updated.
67
- * *lock_version* - Adds "optimistic locking":http://api.rubyonrails.com/classes/ActiveRecord/Locking.html to a model.
68
- * *type* - Specifies that the model uses "Single Table Inheritance":http://api.rubyonrails.com/classes/ActiveRecord/Base.html
67
+ * *lock_version* - Adds "optimistic locking":http://api.rubyonrails.org/classes/ActiveRecord/Locking.html to a model.
68
+ * *type* - Specifies that the model uses "Single Table Inheritance":http://api.rubyonrails.org/classes/ActiveRecord/Base.html
69
69
  * *(table_name)_count* - Used to cache the number of belonging objects on associations. For example, a +comments_count+ column in a +Post+ class that has many instances of +Comment+ will cache the number of existent comments for each post.
70
70
 
71
71
  NOTE: While these column names are optional they are in fact reserved by Active Record. Steer clear of reserved keywords unless you want the extra functionality. For example, "type" is a reserved keyword used to designate a table using Single Table Inheritance. If you are not using STI, try an analogous keyword like "context", that may still accurately describe the data you are modeling.
@@ -483,16 +483,16 @@ SQL uses the +HAVING+ clause to specify conditions on the +GROUP BY+ fields. You
483
483
  For example:
484
484
 
485
485
  <ruby>
486
- Order.group("date(created_at)").having("created_at > ?", 1.month.ago)
486
+ Order.group("date(created_at)").having("created_at < ?", 1.month.ago)
487
487
  </ruby>
488
488
 
489
489
  The SQL that would be executed would be something like this:
490
490
 
491
491
  <sql>
492
- SELECT * FROM orders GROUP BY date(created_at) HAVING created_at > '2009-01-15'
492
+ SELECT * FROM orders GROUP BY date(created_at) HAVING created_at < '2011-04-27'
493
493
  </sql>
494
494
 
495
- This will return single order objects for each day, but only for the last month.
495
+ This will return single order objects for each day, but only those that are at least one month old.
496
496
 
497
497
  h3. Overriding Conditions
498
498
 
@@ -675,7 +675,7 @@ class Post < ActiveRecord::Base
675
675
  has_many :tags
676
676
  end
677
677
 
678
- class Comments < ActiveRecord::Base
678
+ class Comment < ActiveRecord::Base
679
679
  belongs_to :post
680
680
  has_one :guest
681
681
  end
@@ -683,6 +683,10 @@ end
683
683
  class Guest < ActiveRecord::Base
684
684
  belongs_to :comment
685
685
  end
686
+
687
+ class Tag < ActiveRecord::Base
688
+ belongs_to :post
689
+ end
686
690
  </ruby>
687
691
 
688
692
  Now all of the following will produce the expected join queries using +INNER JOIN+:
@@ -700,6 +704,8 @@ SELECT categories.* FROM categories
700
704
  INNER JOIN posts ON posts.category_id = categories.id
701
705
  </sql>
702
706
 
707
+ Or, in English: "return a Category object for all categories with posts". Note that you will see duplicate categories if more than one post has the same category. If you want unique categories, you can use Category.joins(:post).select("distinct(categories.id)").
708
+
703
709
  h5. Joining Multiple Associations
704
710
 
705
711
  <ruby>
@@ -714,18 +720,40 @@ SELECT posts.* FROM posts
714
720
  INNER JOIN comments ON comments.post_id = posts.id
715
721
  </sql>
716
722
 
723
+ Or, in English: "return all posts that have a category and at least one comment". Note again that posts with multiple comments will show up multiple times.
724
+
717
725
  h5. Joining Nested Associations (Single Level)
718
726
 
719
727
  <ruby>
720
728
  Post.joins(:comments => :guest)
721
729
  </ruby>
722
730
 
731
+ This produces:
732
+
733
+ <sql>
734
+ SELECT posts.* FROM posts
735
+ INNER JOIN comments ON comments.post_id = posts.id
736
+ INNER JOIN guests ON guests.comment_id = comments.id
737
+ </sql>
738
+
739
+ Or, in English: "return all posts that have a comment made by a guest."
740
+
723
741
  h5. Joining Nested Associations (Multiple Level)
724
742
 
725
743
  <ruby>
726
744
  Category.joins(:posts => [{:comments => :guest}, :tags])
727
745
  </ruby>
728
746
 
747
+ This produces:
748
+
749
+ <sql>
750
+ SELECT categories.* FROM categories
751
+ INNER JOIN posts ON posts.category_id = categories.id
752
+ INNER JOIN comments ON comments.post_id = posts.id
753
+ INNER JOIN guests ON guests.comment_id = comments.id
754
+ INNER JOIN tags ON tags.post_id = posts.id
755
+ </sql>
756
+
729
757
  h4. Specifying Conditions on the Joined Tables
730
758
 
731
759
  You can specify conditions on the joined tables using the regular "Array":#array-conditions and "String":#pure-string-conditions conditions. "Hash conditions":#hash-conditions provides a special syntax for specifying conditions for the joined tables:
@@ -82,6 +82,7 @@ The following methods skip validations, and will save the object to the database
82
82
  * +increment!+
83
83
  * +increment_counter+
84
84
  * +toggle!+
85
+ * +touch+
85
86
  * +update_all+
86
87
  * +update_attribute+
87
88
  * +update_column+
@@ -428,7 +429,7 @@ end
428
429
 
429
430
  The +validates_with+ helper takes a class, or a list of classes to use for validation. There is no default error message for +validates_with+. You must manually add errors to the record's errors collection in the validator class.
430
431
 
431
- To implement the validate method, you must have an +record+ parameter defined, which is the record to be validated.
432
+ To implement the validate method, you must have a +record+ parameter defined, which is the record to be validated.
432
433
 
433
434
  Like all other validations, +validates_with+ takes the +:if+, +:unless+ and +:on+ options. If you pass any other options, it will send those options to the validator class as +options+:
434
435
 
@@ -914,20 +915,20 @@ h4. Creating an Object
914
915
  * +before_validation+
915
916
  * +after_validation+
916
917
  * +before_save+
917
- * +after_save+
918
918
  * +before_create+
919
919
  * +around_create+
920
920
  * +after_create+
921
+ * +after_save+
921
922
 
922
923
  h4. Updating an Object
923
924
 
924
925
  * +before_validation+
925
926
  * +after_validation+
926
927
  * +before_save+
927
- * +after_save+
928
928
  * +before_update+
929
929
  * +around_update+
930
930
  * +after_update+
931
+ * +after_save+
931
932
 
932
933
  h4. Destroying an Object
933
934
 
@@ -1010,6 +1011,7 @@ Just as with validations, it's also possible to skip callbacks. These methods sh
1010
1011
  * +increment+
1011
1012
  * +increment_counter+
1012
1013
  * +toggle+
1014
+ * +touch+
1013
1015
  * +update_column+
1014
1016
  * +update_all+
1015
1017
  * +update_counters+
@@ -882,7 +882,7 @@ The macro accepts several methods:
882
882
  delegate :name, :age, :address, :twitter, :to => :profile
883
883
  </ruby>
884
884
 
885
- When interpolated into a string, the +:to+ option should become an expression that evaluates to the object the method is delegated to. Typically a string or symbol. Such a expression is evaluated in the context of the receiver:
885
+ When interpolated into a string, the +:to+ option should become an expression that evaluates to the object the method is delegated to. Typically a string or symbol. Such an expression is evaluated in the context of the receiver:
886
886
 
887
887
  <ruby>
888
888
  # delegates to the Rails constant
@@ -3038,7 +3038,7 @@ Date.new(2010, 1, 31).change(:month => 2)
3038
3038
 
3039
3039
  h5(#date-durations). Durations
3040
3040
 
3041
- Durations can be added and substracted to dates:
3041
+ Durations can be added to and subtracted from dates:
3042
3042
 
3043
3043
  <ruby>
3044
3044
  d = Date.current
@@ -3246,7 +3246,7 @@ DateTime.current.change(:month => 2, :day => 30)
3246
3246
 
3247
3247
  h5(#datetime-durations). Durations
3248
3248
 
3249
- Durations can be added and substracted to datetimes:
3249
+ Durations can be added to and subtracted from datetimes:
3250
3250
 
3251
3251
  <ruby>
3252
3252
  now = DateTime.current
@@ -3367,7 +3367,7 @@ If the time to be constructed lies beyond the range supported by +Time+ in the r
3367
3367
 
3368
3368
  h5(#time-durations). Durations
3369
3369
 
3370
- Durations can be added and substracted to time objects:
3370
+ Durations can be added to and subtracted from time objects:
3371
3371
 
3372
3372
  <ruby>
3373
3373
  now = Time.current
@@ -37,8 +37,8 @@ h3. Example Code
37
37
 
38
38
  Choose meaningful examples that depict and cover the basics as well as interesting points or gotchas.
39
39
 
40
- Use two spaces to indent chunks of code.—that is two spaces with respect to the left margin; the examples
41
- themselves should use "Rails code conventions":http://rails.lighthouseapp.com/projects/8994/source-style.
40
+ Use two spaces to indent chunks of code--that is two spaces with respect to the left margin; the examples
41
+ themselves should use "Rails coding conventions":contributing_to_ruby_on_rails.html#follow-the-coding-conventions.
42
42
 
43
43
  Short docs do not need an explicit "Examples" label to introduce snippets, they just follow paragraphs:
44
44
 
@@ -112,7 +112,7 @@ As an example, if you wanted to show all the orders placed on your website in re
112
112
 
113
113
  <ruby>
114
114
  <% Order.find_recent.each do |o| %>
115
- <%= o.buyer.name %> bought <% o.product.name %>
115
+ <%= o.buyer.name %> bought <%= o.product.name %>
116
116
  <% end %>
117
117
 
118
118
  <% cache do %>
@@ -162,17 +162,17 @@ class ProductSweeper < ActionController::Caching::Sweeper
162
162
 
163
163
  # If our sweeper detects that a Product was created call this
164
164
  def after_create(product)
165
- expire_cache_for(product)
165
+ expire_cache_for(product)
166
166
  end
167
167
 
168
168
  # If our sweeper detects that a Product was updated call this
169
169
  def after_update(product)
170
- expire_cache_for(product)
170
+ expire_cache_for(product)
171
171
  end
172
172
 
173
173
  # If our sweeper detects that a Product was deleted call this
174
174
  def after_destroy(product)
175
- expire_cache_for(product)
175
+ expire_cache_for(product)
176
176
  end
177
177
 
178
178
  private
@@ -345,7 +345,7 @@ ActionController::Base.cache_store = MyCacheStore.new
345
345
 
346
346
  h4. Cache Keys
347
347
 
348
- The keys used in a cache can be any object that responds to either +:cache_key+ or to +:to_param+. You can implement the +:cache_key+ method on your classes if you need to generate custom keys. ActiveRecord will generate keys based on the class name and record id.
348
+ The keys used in a cache can be any object that responds to either +:cache_key+ or to +:to_param+. You can implement the +:cache_key+ method on your classes if you need to generate custom keys. Active Record will generate keys based on the class name and record id.
349
349
 
350
350
  You can use Hashes and Arrays of values as cache keys.
351
351
 
@@ -55,7 +55,7 @@ INFO: This output will seem very familiar when we get to the +generate+ command.
55
55
 
56
56
  h4. +rails server+
57
57
 
58
- Let's try it! 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.
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.
59
59
 
60
60
  INFO: WEBrick isn't your only option for serving Rails. We'll get to that in a later section.
61
61
 
@@ -65,7 +65,7 @@ Without any prodding of any kind, +rails server+ will run our new shiny Rails ap
65
65
  $ cd commandsapp
66
66
  $ rails server
67
67
  => Booting WEBrick
68
- => Rails 3.0.0 application starting in development on http://0.0.0.0:3000
68
+ => Rails 3.1.0 application starting in development on http://0.0.0.0:3000
69
69
  => Call with -d to detach
70
70
  => Ctrl-C to shutdown server
71
71
  [2010-04-18 03:20:33] INFO WEBrick 1.3.1
@@ -75,6 +75,8 @@ $ rails server
75
75
 
76
76
  With just three commands we whipped up a Rails server listening on port 3000. Go to your browser and open "http://localhost:3000":http://localhost:3000, you will see a basic Rails app running.
77
77
 
78
+ You can also use the alias "s" to start the server: <tt>rails s</tt>.
79
+
78
80
  h4. +rails generate+
79
81
 
80
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:
@@ -237,7 +239,7 @@ dependency model
237
239
  create test/unit/high_score_test.rb
238
240
  create test/fixtures/high_scores.yml
239
241
  exists db/migrate
240
- create db/migrate/20081217071914_create_high_scores.rb
242
+ create db/migrate/20100209025147_create_high_scores.rb
241
243
  </shell>
242
244
 
243
245
  The generator checks that there exist the directories for models, controllers, helpers, layouts, functional and unit tests, stylesheets, creates the views, controller, model and database migration for HighScore (creating the +high_scores+ table and fields), takes care of the route for the *resource*, and new tests for everything.
@@ -267,11 +269,13 @@ h4. +rails console+
267
269
 
268
270
  The +console+ command lets you interact with your Rails application from the command line. On the underside, +rails console+ uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website.
269
271
 
272
+ You can also use the alias "c" to invoke the console: <tt>rails c</tt>.
273
+
270
274
  If you wish to test out some code without changing any data, you can do that by invoking +rails console --sandbox+.
271
275
 
272
276
  <shell>
273
277
  $ rails console --sandbox
274
- Loading development environment in sandbox (Rails 3.0.0)
278
+ Loading development environment in sandbox (Rails 3.1.0)
275
279
  Any modifications you make will be rolled back on exit
276
280
  irb(main):001:0>
277
281
  </shell>
@@ -280,6 +284,8 @@ h4. +rails dbconsole+
280
284
 
281
285
  +rails dbconsole+ figures out which database you're using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL, PostgreSQL, SQLite and SQLite3.
282
286
 
287
+ You can also use the alias "db" to invoke the dbconsole: <tt>rails db</tt>.
288
+
283
289
  h4. +rails plugin+
284
290
 
285
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.
@@ -306,7 +312,7 @@ $ rails runner "Model.long_running_method"
306
312
 
307
313
  h4. +rails destroy+
308
314
 
309
- Think of +destroy+ as the opposite of +generate+. It'll figure out what generate did, and undo it. Believe you-me, the creation of this tutorial used this command many times!
315
+ Think of +destroy+ as the opposite of +generate+. It'll figure out what generate did, and undo it.
310
316
 
311
317
  <shell>
312
318
  $ rails generate model Oops
@@ -333,9 +339,29 @@ $ rails destroy model Oops
333
339
  notempty app
334
340
  </shell>
335
341
 
336
- h4. +rake about+
342
+ h3. Rake
343
+
344
+ Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility 'make', and uses a 'Rakefile' and +.rake+ files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other.
345
+
346
+ You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing +rake --tasks+. Each task has a description, and should help you find the thing you need.
347
+
348
+ <shell>
349
+ $ rake --tasks
350
+ (in /home/foobar/commandsapp)
351
+ rake db:abort_if_pending_migrations # Raises an error if there are pending migrations
352
+ rake db:charset # Retrieves the charset for the current environment's database
353
+ rake db:collation # Retrieves the collation for the current environment's database
354
+ rake db:create # Create the database defined in config/database.yml for the current Rails.env
355
+ ...
356
+ ...
357
+ rake tmp:pids:clear # Clears all files in tmp/pids
358
+ rake tmp:sessions:clear # Clears all files in tmp/sessions
359
+ rake tmp:sockets:clear # Clears all files in tmp/sockets
360
+ </shell>
361
+
362
+ h4. +about+
337
363
 
338
- Check it: Version numbers for Ruby, RubyGems, Rails, the Rails subcomponents, your application's folder, the current Rails environment name, your app's database adapter, and schema version! +about+ is useful when you need to ask for help, check if a security patch might affect you, or when you need some stats for an existing Rails installation.
364
+ <tt>rake about</tt> gives information about version numbers for Ruby, RubyGems, Rails, the Rails subcomponents, your application's folder, the current Rails environment name, your app's database adapter, and schema version. It is useful when you need to ask for help, check if a security patch might affect you, or when you need some stats for an existing Rails installation.
339
365
 
340
366
  <shell>
341
367
  $ rake about
@@ -343,17 +369,55 @@ About your application's environment
343
369
  Ruby version 1.8.7 (x86_64-linux)
344
370
  RubyGems version 1.3.6
345
371
  Rack version 1.1
346
- Rails version 3.0.0
347
- Active Record version 3.0.0
348
- Action Pack version 3.0.0
349
- Active Resource version 3.0.0
350
- Action Mailer version 3.0.0
351
- Active Support version 3.0.0
372
+ Rails version 3.1.0
373
+ Active Record version 3.1.0
374
+ Action Pack version 3.1.0
375
+ Active Resource version 3.1.0
376
+ Action Mailer version 3.1.0
377
+ Active Support version 3.1.0
352
378
  Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, Rack::Sendfile, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head
353
379
  Application root /home/foobar/commandsapp
354
380
  Environment development
355
381
  </shell>
356
382
 
383
+ h4. +assets+
384
+
385
+ You can precompile the assets in <tt>app/assets</tt> using <tt>rake assets:precompile</tt> and remove compiled assets using <tt>rake assets:clean</tt>.
386
+
387
+ h4. +db+
388
+
389
+ 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
+
391
+ h4. +doc+
392
+
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.
394
+
395
+ h4. +notes+
396
+
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.
398
+
399
+ h4. +routes+
400
+
401
+ +rake routes+ will list all of your defined routes, which is useful for tracking down routing problems in your app, or giving you a good overview of the URLs in an app you're trying to get familiar with.
402
+
403
+ h4. +test+
404
+
405
+ INFO: A good description of unit testing in Rails is given in "A Guide to Testing Rails Applications":testing.html
406
+
407
+ Rails comes with a test suite called Test::Unit. It is through the use of tests that Rails itself is so stable, and the slew of people working on Rails can prove that everything works as it should.
408
+
409
+ The +test:+ namespace helps in running the different tests you will (hopefully!) write.
410
+
411
+ h4. +tmp+
412
+
413
+ The <tt>Rails.root/tmp</tt> directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions. The +tmp:+ namespace tasks will help you clear them if you need to if they've become overgrown, or create them in case of deletions gone awry.
414
+
415
+ h4. Miscellaneous
416
+
417
+ * +rake stats+ is great for looking at statistics on your code, displaying things like KLOCs (thousands of lines of code) and your code to test ratio.
418
+ * +rake secret+ will give you a pseudo-random key to use for your session secret.
419
+ * <tt>rake time:zones:all</tt> lists all the timezones Rails knows about.
420
+
357
421
  h3. The Rails Advanced Command Line
358
422
 
359
423
  More advanced use of the command line is focused around finding useful (even surprising at times) options in the utilities, and fitting those to your needs and specific work flow. Listed here are some tricks up Rails' sleeve.
@@ -437,7 +501,7 @@ Successfully installed mongrel-1.1.5
437
501
  Installing RDoc documentation for mongrel-1.1.5...
438
502
  $ rails server mongrel
439
503
  => Booting Mongrel (use 'rails server webrick' to force WEBrick)
440
- => Rails 3.0.0 application starting on http://0.0.0.0:3000
504
+ => Rails 3.1.0 application starting on http://0.0.0.0:3000
441
505
  ...
442
506
  </shell>
443
507
 
@@ -534,60 +598,3 @@ I got assigned some args:
534
598
  </shell>
535
599
 
536
600
  Tada!
537
-
538
- h4. Rake is Ruby Make
539
-
540
- Rake is a standalone Ruby utility that replaces the Unix utility 'make', and uses a 'Rakefile' and +.rake+ files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other.
541
-
542
- You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing +rake --tasks+. Each task has a description, and should help you find the thing you need.
543
-
544
- <shell>
545
- $ rake --tasks
546
- (in /home/foobar/commandsapp)
547
- rake db:abort_if_pending_migrations # Raises an error if there are pending migrations
548
- rake db:charset # Retrieves the charset for the current environment's database
549
- rake db:collation # Retrieves the collation for the current environment's database
550
- rake db:create # Create the database defined in config/database.yml for the current Rails.env
551
- ...
552
- ...
553
- rake tmp:pids:clear # Clears all files in tmp/pids
554
- rake tmp:sessions:clear # Clears all files in tmp/sessions
555
- rake tmp:sockets:clear # Clears all files in tmp/sockets
556
- </shell>
557
-
558
- h5. +db:+ Database
559
-
560
- 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.
561
-
562
- h5. +doc:+ Documentation
563
-
564
- 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.
565
-
566
- h5. +notes:+ Code note enumeration
567
-
568
- 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.
569
-
570
- h5. +test:+ Rails tests
571
-
572
- INFO: A good description of unit testing in Rails is given in "A Guide to Testing Rails Applications":testing.html
573
-
574
- Rails comes with a test suite called Test::Unit. It is through the use of tests that Rails itself is so stable, and the slew of people working on Rails can prove that everything works as it should.
575
-
576
- The +test:+ namespace helps in running the different tests you will (hopefully!) write.
577
-
578
- h5. +time:+ Timezones
579
-
580
- You can list all the timezones Rails knows about with +rake time:zones:all+, which is useful just in day-to-day life.
581
-
582
- h5. +tmp:+ Temporary files
583
-
584
- The tmp directory is, like in the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions. The +tmp:+ namespace tasks will help you clear them if you need to if they've become overgrown, or create them in case of deletions gone awry.
585
-
586
- h5. Miscellaneous Tasks
587
-
588
- +rake stats+ is great for looking at statistics on your code, displaying things like KLOCs (thousands of lines of code) and your code to test ratio.
589
-
590
- +rake secret+ will give you a pseudo-random key to use for your session secret.
591
-
592
- +rake routes+ will list all of your defined routes, which is useful for tracking down routing problems in your app, or giving you a good overview of the URLs in an app you're trying to get familiar with.
593
-