aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/RUNNING_UNIT_TESTS2
-rw-r--r--actionpack/lib/abstract_controller/callbacks.rb2
-rwxr-xr-x[-rw-r--r--]activesupport/lib/active_support/core_ext/object/to_param.rb4
-rw-r--r--railties/Rakefile6
-rw-r--r--railties/guides/source/activerecord_validations_callbacks.textile7
-rw-r--r--railties/guides/source/contribute.textile1
-rw-r--r--railties/guides/source/credits.html.erb2
-rw-r--r--railties/guides/source/form_helpers.textile8
-rw-r--r--railties/guides/source/getting_started.textile3
-rw-r--r--railties/guides/source/initialization.textile66
-rw-r--r--railties/guides/w3c_validator.rb67
11 files changed, 151 insertions, 17 deletions
diff --git a/actionpack/RUNNING_UNIT_TESTS b/actionpack/RUNNING_UNIT_TESTS
index 16b119878a..95a8bc7497 100644
--- a/actionpack/RUNNING_UNIT_TESTS
+++ b/actionpack/RUNNING_UNIT_TESTS
@@ -11,7 +11,7 @@ Rake can be found at http://rake.rubyforge.org
If you only want to run a single test suite, or don't want to bother with Rake,
you can do so with something like:
- ruby controller/base_tests.rb
+ ruby -Itest test/controller/base_tests.rb
== Dependency on ActiveRecord and database setup
diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb
index ee496dadc5..67efeb7063 100644
--- a/actionpack/lib/abstract_controller/callbacks.rb
+++ b/actionpack/lib/abstract_controller/callbacks.rb
@@ -20,7 +20,7 @@ module AbstractController
end
module ClassMethods
- # If :only or :accept are used, convert the options into the
+ # If :only or :except are used, convert the options into the
# primitive form (:per_key) used by ActiveSupport::Callbacks.
# The basic idea is that :only => :index gets converted to
# :if => proc {|c| c.action_name == "index" }, but that the
diff --git a/activesupport/lib/active_support/core_ext/object/to_param.rb b/activesupport/lib/active_support/core_ext/object/to_param.rb
index 49e41e919a..06f077e920 100644..100755
--- a/activesupport/lib/active_support/core_ext/object/to_param.rb
+++ b/activesupport/lib/active_support/core_ext/object/to_param.rb
@@ -38,9 +38,9 @@ class Hash
# passed to enclose the param names (see example below).
#
# ==== Examples
- # { :name => 'David', :nationality => 'Danish' }.to_query # => "name=David&nationality=Danish"
+ # { :name => 'David', :nationality => 'Danish' }.to_param # => "name=David&nationality=Danish"
#
- # { :name => 'David', :nationality => 'Danish' }.to_query('user') # => "user[name]=David&user[nationality]=Danish"
+ # { :name => 'David', :nationality => 'Danish' }.to_param('user') # => "user[name]=David&user[nationality]=Danish"
def to_param(namespace = nil)
collect do |key, value|
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
diff --git a/railties/Rakefile b/railties/Rakefile
index daffd8ce30..efdb31cbd8 100644
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -50,6 +50,12 @@ task :update_prototype_ujs do
system "curl http://github.com/rails/prototype-ujs/raw/master/src/rails.js > lib/rails/generators/rails/app/templates/public/javascripts/rails.js"
end
+# Validate guides -------------------------------------------------------------------------
+desc 'Validate guides, use ONLY=foo to process just "foo.html"'
+task :validate_guides do
+ ruby "guides/w3c_validator.rb"
+end
+
# Generate documentation ------------------------------------------------------------------
Rake::RDocTask.new { |rdoc|
diff --git a/railties/guides/source/activerecord_validations_callbacks.textile b/railties/guides/source/activerecord_validations_callbacks.textile
index ee30f3963b..857551c9d5 100644
--- a/railties/guides/source/activerecord_validations_callbacks.textile
+++ b/railties/guides/source/activerecord_validations_callbacks.textile
@@ -139,7 +139,7 @@ end
+invalid?+ is simply the inverse of +valid?+. +invalid?+ triggers your validations and returns true if any errors were added to the object, and false otherwise.
-h4. +errors[]+
+h4(#validations_overview-errors). +errors[]+
To verify whether or not a particular attribute of an object is valid, you can use +errors[:attribute]+ that returns an array with all attribute errors, when there are no errors on the specified attribute, an empty array is returned.
@@ -597,7 +597,7 @@ In addition to the +valid?+ and +invalid?+ methods covered earlier, Rails provid
The following is a list of the most commonly used methods. Please refer to the +ActiveRecord::Errors+ documentation for a list of all the available methods.
-h4. +errors+
+h4(#working_with_validation_errors-errors). +errors+
Returns an OrderedHash with all errors. Each key is the attribute name and value is an array of strings with all errors.
@@ -617,7 +617,7 @@ person.valid? # => true
person.errors # => []
</ruby>
-h4. +errors[]+
+h4(#working_with_validation_errors-errors-2). +errors[]+
+errors[]+ is used when you want to check the error messages for a specific attribute. It returns an array of strings with all error messages for the given attribute, each string with one error message. If there are no errors related to the attribute returns an empty array.
@@ -1162,6 +1162,7 @@ h3. Changelog
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks
+* May 24, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
* May 15, 2010: Validation Errors section updated by "Emili Parreño":http://www.eparreno.com
* March 7, 2009: Callbacks revision by Trevor Turk
* February 10, 2009: Observers revision by Trevor Turk
diff --git a/railties/guides/source/contribute.textile b/railties/guides/source/contribute.textile
index 66f24e5c7e..88c5c79e9d 100644
--- a/railties/guides/source/contribute.textile
+++ b/railties/guides/source/contribute.textile
@@ -14,6 +14,7 @@ h3. How to Contribute?
* Sample format : "Active Record Associations":http://github.com/lifo/docrails/blob/3e56a3832415476fdd1cb963980d0ae390ac1ed3/railties/guides/source/association_basics.textile.
* Sample output : "Active Record Associations":association_basics.html.
* You can build the Guides during testing by running +rake generate_guides+ in the +railties+ directory.
+* You're encouraged to validate XHTML for the generated guides before commiting your changes by running +rake validate_guides+ in the +railties+ directory.
* Edge guides "can be consulted online":http://edgeguides.rubyonrails.org/. That website is generated periodically from docrails.
h3. What to Contribute?
diff --git a/railties/guides/source/credits.html.erb b/railties/guides/source/credits.html.erb
index e9eb31bcae..825e042628 100644
--- a/railties/guides/source/credits.html.erb
+++ b/railties/guides/source/credits.html.erb
@@ -44,7 +44,7 @@ Ruby on Rails Guides: Credits
<% end %>
<%= author('Mikel Lindsaar', 'raasdnil') do %>
- Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby <a hred="http://github.com/mikel/mail">Mail gem</a> and core contributor (he helped re-write Action Mailer's API). Mikel is the founder of <a href="http://rubyx.com/">RubyX</a>, has a <a href="http://lindsaar.net/">blog</a> and <a href="http://twitter.com/raasdnil">tweets</a>.
+ Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby <a href="http://github.com/mikel/mail">Mail gem</a> and core contributor (he helped re-write Action Mailer's API). Mikel is the founder of <a href="http://rubyx.com/">RubyX</a>, has a <a href="http://lindsaar.net/">blog</a> and <a href="http://twitter.com/raasdnil">tweets</a>.
<% end %>
<%= author('Cássio Marques', 'cmarques') do %>
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index 0c0a4e2263..515b3aad39 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -255,7 +255,7 @@ You can create a similar binding without actually creating +&lt;form&gt;+ tags
<erb>
<%= form_for :person, @person, :url => { :action => "create" } do |person_form| %>
<%= person_form.text_field :name %>
- <% fields_for @person.contact_detail do |contact_details_form| %>
+ <%= fields_for @person.contact_detail do |contact_details_form| %>
<%= contact_details_form.text_field :phone_number %>
<% end %>
<% end %>
@@ -697,7 +697,7 @@ You might want to render a form with a set of edit fields for each of a person's
<%= form_for @person do |person_form| %>
<%= person_form.text_field :name %>
<% for address in @person.addresses %>
- <% person_form.fields_for address, :index => address do |address_form|%>
+ <%= person_form.fields_for address, :index => address do |address_form|%>
<%= address_form.text_field :city %>
<% end %>
<% end %>
@@ -725,7 +725,7 @@ Rails knows that all these inputs should be part of the person hash because you
To create more intricate nestings, you can specify the first part of the input name (+person[address]+ in the previous example) explicitly, for example
<erb>
-<% fields_for 'person[address][primary]', address, :index => address do |address_form| %>
+<%= fields_for 'person[address][primary]', address, :index => address do |address_form| %>
<%= address_form.text_field :city %>
<% end %>
</erb>
@@ -741,7 +741,7 @@ As a general rule the final input name is the concatenation of the name given to
As a shortcut you can append [] to the name and omit the +:index+ option. This is the same as specifying +:index => address+ so
<erb>
-<% fields_for 'person[address][primary][]', address do |address_form| %>
+<%= fields_for 'person[address][primary][]', address do |address_form| %>
<%= address_form.text_field :city %>
<% end %>
</erb>
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index dd4e94a9e1..fe623e969f 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1486,8 +1486,7 @@ h3. Changelog
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/2
-* May 16, 2010: Added a section on configuration gotchas to address common encoding
- problems that people might have
+* May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by "Yehuda Katz":http://www.yehudakatz.com
* April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com
* April 25, 2010: Couple of more minor fixups "Mikel Lindsaar":credits.html#raasdnil
* April 1, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 96d6998e1c..cccbb9df06 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -1819,7 +1819,7 @@ On the surface, this looks like a simple class inheritance. There's more underne
end
</ruby>
-We do not already have a +Rails.application+, so instead this resorts to calling +super+. +Rails::Application+ descends from +Rails::Engine+ and so will call the +inherited+ method in +Rails::Engine+, but before that it's important to note that +called_from+ is defined an +attr_accessor+ on +Rails::Engine+:
+We do not already have a +Rails.application+, so instead this resorts to calling +super+. +Rails::Application+ descends from +Rails::Engine+ and so will call the +inherited+ method in +Rails::Engine+ (in _railties/lib/rails/engine.rb_), but before that it's important to note that +called_from+ is defined an +attr_accessor+ on +Rails::Engine+ and that +YourApp::Application+ is not an +abstract_railtie+:
<ruby>
def inherited(base)
@@ -1835,8 +1835,68 @@ We do not already have a +Rails.application+, so instead this resorts to calling
end
</ruby>
-This +called_from+ setting looks a little overwhelming to begin with, but the short end of it is that it returns the route to your application's config directory, something like: _/home/you/yourapp/config_. After +called_from+ has been set, +super+ is again called and this means the +Rails::Railtie#inherited+ method.
-
+This +called_from+ setting looks a little overwhelming to begin with, but the short end of it is that it returns the route to your application's config directory, something like: _/home/you/yourapp/config_. After +called_from+ has been set, +super+ is again called and this means the +Rails::Railtie#inherited+ method (in _railties/lib/rails/railtie.rb_):
+
+<ruby>
+ def inherited(base)
+ unless base.abstract_railtie?
+ base.send(:include, self::Configurable)
+ subclasses << base
+ end
+ end
+</ruby>
+
+Again, +YourApp::Application+ will return false for +abstract_railtie+ and so the code inside the +unless+ will be ran. The first line:
+
+<ruby>
+ base.send(:include, self::Configurable)
+</ruby>
+
+includes the +self::Configurable+ module, with self being +Rails::Application+ in this context:
+
+<ruby>
+ module Rails
+ class Application
+ module Configurable
+ def self.included(base)
+ base.extend ClassMethods
+ end
+
+ module ClassMethods
+ def inherited(base)
+ raise "You cannot inherit from a Rails::Application child"
+ end
+ end
+
+ def config
+ @config ||= Application::Configuration.new(self.class.find_root_with_flag("config.ru", Dir.pwd))
+ end
+ end
+ end
+ end
+</ruby>
+
+The inclusion of the +Rails::Application::Configurable+ module triggers the +included+ method in here which extends +YourApp::Application+ with the +Rails::Application::Configurable::ClassMethods+.
+
+Now that the chain of +super+ calls is done, we'll go back to the original +inherited+ method in +Rails::Application+ and the final line in this method:
+
+<ruby>
+ Rails.application = base.instance
+</ruby>
+
++base+ in this case is +YourApp::Application+ and calling +instance+ on this will return an instance of +YourApp::Application+ through the +instance+ method defined here:
+
+<ruby>
+ def instance
+ if self == Rails::Application
+ Rails.application
+ else
+ @@instance ||= new
+ end
+ end
+</ruby>
+
++self+ in this case is +YourApp::Application+, so it won't match to +Rails::Application+ so instead the +new+ method is called which calls the +initialize+ method.
diff --git a/railties/guides/w3c_validator.rb b/railties/guides/w3c_validator.rb
new file mode 100644
index 0000000000..b55645a7a9
--- /dev/null
+++ b/railties/guides/w3c_validator.rb
@@ -0,0 +1,67 @@
+# ---------------------------------------------------------------------------
+#
+# This script validates the generated guides against the W3C Validator.
+#
+# Guides are taken from the output directory, from where all .html files are
+# submitted to the validator.
+#
+# This script is prepared to be launched from the railties directory as a rake task:
+#
+# rake validate_guides
+#
+# If nothing is specified, all files will be validated, but you can check just
+# some of them using this environment variable:
+#
+# ONLY
+# Use ONLY if you want to validate only one or a set of guides. Prefixes are
+# enough:
+#
+# # validates only association_basics.html
+# ONLY=assoc rake validate_guides
+#
+# Separate many using commas:
+#
+# # validates only
+# ONLY=assoc,migrations rake validate_guides
+#
+# ---------------------------------------------------------------------------
+
+require 'rubygems'
+require 'w3c_validators'
+include W3CValidators
+
+module RailsGuides
+ class Validator
+
+ def validate
+ validator = MarkupValidator.new
+
+ guides_to_validate.each do |f|
+ puts "Validating #{f}"
+ results = validator.validate_file(f)
+
+ if !results.validity
+ puts "#{f} FAILED W3C validation with #{results.errors.size} error(s):"
+ results.errors.each do |error|
+ puts error.to_s
+ end
+ end
+ end
+ end
+
+ private
+ def guides_to_validate
+ guides = Dir["./guides/output/*.html"]
+ ENV.key?('ONLY') ? select_only(guides) : guides
+ end
+
+ def select_only(guides)
+ prefixes = ENV['ONLY'].split(",").map(&:strip)
+ guides.select do |guide|
+ prefixes.any? {|p| guide.start_with?("./guides/output/#{p}")}
+ end
+ end
+ end
+end
+
+RailsGuides::Validator.new.validate \ No newline at end of file