Merge remote branch 'docrails/master'

This commit is contained in:
Xavier Noria 2010-09-03 21:30:22 +02:00
commit 93acbf6bf3
7 changed files with 30 additions and 24 deletions

@ -13,7 +13,7 @@ module Helpers #:nodoc:
module UrlHelper
# This helper may be included in any class that includes the
# URL helpers of a routes (routes.url_helpers). Some methods
# provided here will only work in the4 context of a request
# provided here will only work in the context of a request
# (link_to_unless_current, for instance), which must be provided
# as a method called #request on the context.

@ -161,7 +161,7 @@ def clear_aggregation_cache #:nodoc:
# by specifying an instance of the value object in the conditions hash. The following example
# finds all customers with +balance_amount+ equal to 20 and +balance_currency+ equal to "USD":
#
# Customer.find(:all, :conditions => {:balance => Money.new(20, "USD")})
# Customer.where(:balance => Money.new(20, "USD")).all
#
module ClassMethods
# Adds reader and writer methods for manipulating a value object:

@ -602,7 +602,7 @@ def association_instance_set(name, association)
# other than the main one. If this is the case Active Record falls back to the previously
# used LEFT OUTER JOIN based strategy. For example
#
# Post.find(:all, :include => [ :author, :comments ], :conditions => ['comments.approved = ?', true])
# Post.includes([:author, :comments]).where(['comments.approved = ?', true]).all
#
# This will result in a single SQL query with joins along the lines of:
# <tt>LEFT OUTER JOIN comments ON comments.post_id = posts.id</tt> and

@ -14,8 +14,8 @@ module Locking
# Example:
# Account.transaction do
# # select * from accounts where name = 'shugo' limit 1 for update
# shugo = Account.find(:first, :conditions => "name = 'shugo'", :lock => true)
# yuko = Account.find(:first, :conditions => "name = 'yuko'", :lock => true)
# shugo = Account.where("name = 'shugo'").lock(true).first
# yuko = Account.where("name = 'shugo'").lock(true).first
# shugo.balance -= 100
# shugo.save!
# yuko.balance += 100
@ -26,7 +26,7 @@ module Locking
# This may be better if you don't need to lock every row. Example:
# Account.transaction do
# # select * from accounts where ...
# accounts = Account.find(:all, :conditions => ...)
# accounts = Account.where(...).all
# account1 = accounts.detect { |account| ... }
# account2 = accounts.detect { |account| ... }
# # select * from accounts where id=? for update

@ -14,9 +14,9 @@ module Calculations
#
# * <tt>:conditions</tt>: An SQL fragment like "administrator = 1" or [ "user_name = ?", username ].
# See conditions in the intro to ActiveRecord::Base.
# * <tt>:joins</tt>: Either an SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id"
# * <tt>:joins</tt>: Either an SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id"
# (rarely needed) or named associations in the same form used for the <tt>:include</tt> option, which will
# perform an INNER JOIN on the associated table(s). If the value is a string, then the records
# perform an INNER JOIN on the associated table(s). If the value is a string, then the records
# will be returned read-only since they will have attributes that do not correspond to the table's columns.
# Pass <tt>:readonly => false</tt> to override.
# * <tt>:include</tt>: Named associations that should be loaded alongside using LEFT OUTER JOINs.

@ -21,7 +21,7 @@ module FinderMethods
#
# ==== Parameters
#
# * <tt>:conditions</tt> - An SQL fragment like "administrator = 1", <tt>[ "user_name = ?", username ]</tt>,
# * <tt>:conditions</tt> - An SQL fragment like "administrator = 1", <tt>["user_name = ?", username]</tt>,
# or <tt>["user_name = :user_name", { :user_name => user_name }]</tt>. See conditions in the intro.
# * <tt>:order</tt> - An SQL fragment like "created_at DESC, name".
# * <tt>:group</tt> - An attribute name by which the result should be grouped. Uses the <tt>GROUP BY</tt> SQL-clause.
@ -54,7 +54,7 @@ module FinderMethods
# Person.find(1, 2, 6) # returns an array for objects with IDs in (1, 2, 6)
# Person.find([7, 17]) # returns an array for objects with IDs in (7, 17)
# Person.find([1]) # returns an array for the object with ID = 1
# Person.find(1, :conditions => "administrator = 1", :order => "created_on DESC")
# Person.where("administrator = 1").order("created_on DESC").find(1)
#
# Note that returned records may not be in the same order as the ids you
# provide since database rows are unordered. Give an explicit <tt>:order</tt>
@ -63,23 +63,23 @@ module FinderMethods
# ==== Examples
#
# # find first
# Person.find(:first) # returns the first object fetched by SELECT * FROM people
# Person.find(:first, :conditions => [ "user_name = ?", user_name])
# Person.find(:first, :conditions => [ "user_name = :u", { :u => user_name }])
# Person.find(:first, :order => "created_on DESC", :offset => 5)
# Person.first # returns the first object fetched by SELECT * FROM people
# Person.where(["user_name = ?", user_name]).first
# Person.where(["user_name = :u", { :u => user_name }]).first
# Person.order("created_on DESC").offset(5).first
#
# # find last
# Person.find(:last) # returns the last object fetched by SELECT * FROM people
# Person.find(:last, :conditions => [ "user_name = ?", user_name])
# Person.find(:last, :order => "created_on DESC", :offset => 5)
# Person.last # returns the last object fetched by SELECT * FROM people
# Person.where(["user_name = ?", user_name]).last
# Person.order("created_on DESC").offset(5).last
#
# # find all
# Person.find(:all) # returns an array of objects for all the rows fetched by SELECT * FROM people
# Person.find(:all, :conditions => [ "category IN (?)", categories], :limit => 50)
# Person.find(:all, :conditions => { :friends => ["Bob", "Steve", "Fred"] }
# Person.find(:all, :offset => 10, :limit => 10)
# Person.find(:all, :include => [ :account, :friends ])
# Person.find(:all, :group => "category")
# Person.all # returns an array of objects for all the rows fetched by SELECT * FROM people
# Person.where(["category IN (?)", categories]).limit(50).all
# Person.where({ :friends => ["Bob", "Steve", "Fred"] }).all
# Person.offset(10).limit(10).all
# Person.includes([:account, :friends]).all
# Person.group("category").all
#
# Example for find with a lock: Imagine two concurrent transactions:
# each will read <tt>person.visits == 2</tt>, add 1 to it, and save, resulting
@ -88,7 +88,7 @@ module FinderMethods
# expected <tt>person.visits == 4</tt>.
#
# Person.transaction do
# person = Person.find(1, :lock => true)
# person = Person.lock(true).find(1)
# person.visits += 1
# person.save!
# end

@ -686,6 +686,8 @@ The key for the error message in this case is +:blank+. Active Record will look
activerecord.errors.models.[model_name].attributes.[attribute_name]
activerecord.errors.models.[model_name]
activerecord.errors.messages
errors.attributes.[attribute_name]
errors.messages
</ruby>
Thus, in our example it will try the following keys in this order and return the first result:
@ -694,6 +696,8 @@ Thus, in our example it will try the following keys in this order and return the
activerecord.errors.models.user.attributes.name.blank
activerecord.errors.models.user.blank
activerecord.errors.messages.blank
errors.attributes.name.blank
errors.messagges.blank
</ruby>
When your models are additionally using inheritance then the messages are looked up in the inheritance chain.
@ -714,6 +718,8 @@ activerecord.errors.models.admin.blank
activerecord.errors.models.user.attributes.title.blank
activerecord.errors.models.user.blank
activerecord.errors.messages.blank
errors.attributes.title.blank
errors.messagges.blank
</ruby>
This way you can provide special translations for various error messages at different points in your models inheritance chain and in the attributes, models, or default scopes.