mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge branch 'master' of github.com:lifo/docrails
This commit is contained in:
commit
7c29246b8c
7 changed files with 27 additions and 20 deletions
|
@ -121,7 +121,7 @@ module ActionController
|
|||
#
|
||||
# def search
|
||||
# @results = Search.find(params[:query])
|
||||
# case @results
|
||||
# case @results.count
|
||||
# when 0 then render :action => "no_results"
|
||||
# when 1 then render :action => "show"
|
||||
# when 2..10 then render :action => "show_many"
|
||||
|
|
|
@ -251,6 +251,7 @@ module ActionController
|
|||
# def test_create
|
||||
# json = {:book => { :title => "Love Hina" }}.to_json
|
||||
# post :create, json
|
||||
# end
|
||||
#
|
||||
# == Special instance variables
|
||||
#
|
||||
|
|
|
@ -37,7 +37,7 @@ module ActiveModel
|
|||
# attribute.
|
||||
#
|
||||
# NOTE: This check is performed only if +password_confirmation+ is not
|
||||
# +nil+, and by default only on save. To require confirmation, make sure
|
||||
# +nil+. To require confirmation, make sure
|
||||
# to add a presence check for the confirmation attribute:
|
||||
#
|
||||
# validates_presence_of :password_confirmation, :if => :password_changed?
|
||||
|
|
|
@ -44,7 +44,8 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
# Defines the primary key field -- can be overridden in subclasses. Overwriting will negate any effect of the
|
||||
# primary_key_prefix_type setting, though.
|
||||
# primary_key_prefix_type setting, though. Since primary keys are usually protected from mass assignment,
|
||||
# remember to let your database generate them or include the key in +attr_accessible+.
|
||||
def primary_key
|
||||
@primary_key = reset_primary_key unless defined? @primary_key
|
||||
@primary_key
|
||||
|
|
|
@ -93,6 +93,16 @@ module ActiveRecord
|
|||
relation
|
||||
end
|
||||
|
||||
# Replaces any existing order defined on the relation with the specified order.
|
||||
#
|
||||
# User.order('email DESC').reorder('id ASC') # generated SQL has 'ORDER BY id ASC'
|
||||
#
|
||||
# Subsequent calls to order on the same relation will be appended. For example:
|
||||
#
|
||||
# User.order('email DESC').reorder('id ASC').order('name ASC')
|
||||
#
|
||||
# generates a query with 'ORDER BY id ASC, name ASC'.
|
||||
#
|
||||
def reorder(*args)
|
||||
return self if args.blank?
|
||||
|
||||
|
|
|
@ -376,7 +376,7 @@ NOTE: Defined in +active_support/core_ext/object/instance_variables.rb+.
|
|||
h5. +instance_values+
|
||||
|
||||
The method +instance_values+ returns a hash that maps instance variable names without "@" to their
|
||||
corresponding values. Keys are strings both in Ruby 1.8 and 1.9:
|
||||
corresponding values. Keys are strings:
|
||||
|
||||
<ruby>
|
||||
class C
|
||||
|
@ -704,13 +704,11 @@ module X
|
|||
end
|
||||
end
|
||||
|
||||
X.local_constants # => ["X2", "X1", "Y"], assumes Ruby 1.8
|
||||
X::Y.local_constants # => ["X1", "Y1"], assumes Ruby 1.8
|
||||
X.local_constants # => [:X1, :X2, :Y]
|
||||
X::Y.local_constants # => [:Y1, :X1]
|
||||
</ruby>
|
||||
|
||||
The names are returned as strings in Ruby 1.8, and as symbols in Ruby 1.9. The method +local_constant_names+ always returns strings.
|
||||
|
||||
WARNING: This method returns precise results in Ruby 1.9. In older versions of Ruby, however, it may miss some constants in case the same constant exists in the receiver module as well as in any of its ancestors and both constants point to the same object (objects are compared using +Object#object_id+).
|
||||
The names are returned as symbols. The method +local_constant_names+ always returns strings.
|
||||
|
||||
NOTE: Defined in +active_support/core_ext/module/introspection.rb+.
|
||||
|
||||
|
@ -737,8 +735,8 @@ Math.qualified_const_get("E") # => 2.718281828459045
|
|||
</ruby>
|
||||
|
||||
These methods are analogous to their builtin counterparts. In particular,
|
||||
+qualified_constant_defined?+ accepts an optional second argument in 1.9
|
||||
to be able to say whether you want the predicate to look in the ancestors.
|
||||
+qualified_constant_defined?+ accepts an optional second argument to be
|
||||
able to say whether you want the predicate to look in the ancestors.
|
||||
This flag is taken into account for each constant in the expression while
|
||||
walking down the path.
|
||||
|
||||
|
@ -759,12 +757,12 @@ end
|
|||
+qualified_const_defined?+ behaves this way:
|
||||
|
||||
<ruby>
|
||||
N.qualified_const_defined?("C::X", false) # => false (1.9 only)
|
||||
N.qualified_const_defined?("C::X", true) # => true (1.9 only)
|
||||
N.qualified_const_defined?("C::X") # => false in 1.8, true in 1.9
|
||||
N.qualified_const_defined?("C::X", false) # => false
|
||||
N.qualified_const_defined?("C::X", true) # => true
|
||||
N.qualified_const_defined?("C::X") # => true
|
||||
</ruby>
|
||||
|
||||
As the last example implies, in 1.9 the second argument defaults to true,
|
||||
As the last example implies, the second argument defaults to true,
|
||||
as in +const_defined?+.
|
||||
|
||||
For coherence with the builtin methods only relative paths are accepted.
|
||||
|
@ -2238,9 +2236,6 @@ The last point is particularly worth comparing for some enumerables:
|
|||
<ruby>
|
||||
Array.wrap(:foo => :bar) # => [{:foo => :bar}]
|
||||
Array(:foo => :bar) # => [[:foo, :bar]]
|
||||
|
||||
Array.wrap("foo\nbar") # => ["foo\nbar"]
|
||||
Array("foo\nbar") # => ["foo\n", "bar"], in Ruby 1.8
|
||||
</ruby>
|
||||
|
||||
There's also a related idiom that uses the splat operator:
|
||||
|
|
|
@ -380,7 +380,7 @@ Now you need to get other people to look at your patch, just as you've looked at
|
|||
|
||||
h4. Iterate as Necessary
|
||||
|
||||
It’s entirely possible that the feedback you get will suggest changes. Don’t get discouraged: the whole point of contributing to an active open source project is to tap into community knowledge. If people are encouraging you to tweak your code, then it’s worth making the tweaks and resubmitting. If the feedback is that your code doesn’t belong in the core, you might still think about releasing it as a plugin.
|
||||
It’s entirely possible that the feedback you get will suggest changes. Don’t get discouraged: the whole point of contributing to an active open source project is to tap into community knowledge. If people are encouraging you to tweak your code, then it’s worth making the tweaks and resubmitting. If the feedback is that your code doesn’t belong in the core, you might still think about releasing it as a gem.
|
||||
|
||||
And then ... think about your next contribution!
|
||||
|
||||
|
|
Loading…
Reference in a new issue