Skip to content

Commit 523d0f0

Browse files
committed
Merge branch 'master' of github.com:lifo/docrails
2 parents cf992fb + 903a9d5 commit 523d0f0

File tree

5 files changed

+68
-17
lines changed

5 files changed

+68
-17
lines changed

activerecord/lib/active_record/associations/collection_proxy.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,27 @@ class CollectionProxy < Relation
636636
#
637637
# Pet.find(4, 5, 6) # => ActiveRecord::RecordNotFound: Couldn't find all Pets with IDs (4, 5, 6)
638638

639+
##
640+
# :method: uniq
641+
#
642+
# :call-seq:
643+
# uniq()
644+
#
645+
# Specifies whether the records should be unique or not.
646+
#
647+
# class Person < ActiveRecord::Base
648+
# has_many :pets
649+
# end
650+
#
651+
# person.pets.select(:name)
652+
# # => [
653+
# # #<Pet name: "Fancy-Fancy">,
654+
# # #<Pet name: "Fancy-Fancy">
655+
# # ]
656+
#
657+
# person.pets.select(:name).uniq
658+
# # => [#<Pet name: "Fancy-Fancy">]
659+
639660
##
640661
# :method: count
641662
#

activerecord/lib/active_record/core.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ module Core
1010
included do
1111
##
1212
# :singleton-method:
13-
# Accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class,
14-
# which is then passed on to any new database connections made and which can be retrieved on both
15-
# a class and instance level by calling +logger+.
13+
#
14+
# Accepts a logger conforming to the interface of Log4r which is then
15+
# passed on to any new database connections made and which can be
16+
# retrieved on both a class and instance level by calling +logger+.
1617
config_attribute :logger, :global => true
1718

1819
##

activesupport/lib/active_support/core_ext/hash/keys.rb

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
class Hash
22
# Return a new hash with all keys converted using the block operation.
33
#
4-
# { :name => 'Rob', :years => '28' }.transform_keys{ |key| key.to_s.upcase }
5-
# # => { "NAME" => "Rob", "YEARS" => "28" }
4+
# hash = { name: 'Rob', age: '28' }
5+
#
6+
# hash.transform_keys{ |key| key.to_s.upcase }
7+
# # => { "NAME" => "Rob", "AGE" => "28" }
68
def transform_keys
79
result = {}
810
keys.each do |key|
@@ -22,8 +24,10 @@ def transform_keys!
2224

2325
# Return a new hash with all keys converted to strings.
2426
#
25-
# { :name => 'Rob', :years => '28' }.stringify_keys
26-
# #=> { "name" => "Rob", "years" => "28" }
27+
# hash = { name: 'Rob', age: '28' }
28+
#
29+
# hash.stringify_keys
30+
# #=> { "name" => "Rob", "age" => "28" }
2731
def stringify_keys
2832
transform_keys{ |key| key.to_s }
2933
end
@@ -37,8 +41,10 @@ def stringify_keys!
3741
# Return a new hash with all keys converted to symbols, as long as
3842
# they respond to +to_sym+.
3943
#
40-
# { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
41-
# #=> { :name => "Rob", :years => "28" }
44+
# hash = { 'name' => 'Rob', 'age' => '28' }
45+
#
46+
# hash.symbolize_keys
47+
# #=> { name: "Rob", age: "28" }
4248
def symbolize_keys
4349
transform_keys{ |key| key.to_sym rescue key }
4450
end
@@ -69,8 +75,10 @@ def assert_valid_keys(*valid_keys)
6975
# This includes the keys from the root hash and from all
7076
# nested hashes.
7177
#
72-
# { :person => { :name => 'Rob', :years => '28' } }.deep_transform_keys{ |key| key.to_s.upcase }
73-
# # => { "PERSON" => { "NAME" => "Rob", "YEARS" => "28" } }
78+
# hash = { person: { name: 'Rob', age: '28' } }
79+
#
80+
# hash.deep_transform_keys{ |key| key.to_s.upcase }
81+
# # => { "PERSON" => { "NAME" => "Rob", "AGE" => "28" } }
7482
def deep_transform_keys(&block)
7583
result = {}
7684
each do |key, value|
@@ -93,6 +101,11 @@ def deep_transform_keys!(&block)
93101
# Return a new hash with all keys converted to strings.
94102
# This includes the keys from the root hash and from all
95103
# nested hashes.
104+
#
105+
# hash = { person: { name: 'Rob', age: '28' } }
106+
#
107+
# hash.deep_stringify_keys
108+
# # => { "person" => { "name" => "Rob", "age" => "28" } }
96109
def deep_stringify_keys
97110
deep_transform_keys{ |key| key.to_s }
98111
end
@@ -107,6 +120,11 @@ def deep_stringify_keys!
107120
# Return a new hash with all keys converted to symbols, as long as
108121
# they respond to +to_sym+. This includes the keys from the root hash
109122
# and from all nested hashes.
123+
#
124+
# hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
125+
#
126+
# hash.deep_symbolize_keys
127+
# # => { person: { name: "Rob", age: "28" } }
110128
def deep_symbolize_keys
111129
deep_transform_keys{ |key| key.to_sym rescue key }
112130
end

activesupport/lib/active_support/core_ext/module/attribute_accessors.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ def #{sym}=(obj)
4848
#
4949
# module AppConfiguration
5050
# mattr_accessor :google_api_key
51-
# self.google_api_key = "123456789"
5251
#
53-
# mattr_accessor :paypal_url
54-
# self.paypal_url = "www.sandbox.paypal.com"
52+
# self.google_api_key = "123456789"
5553
# end
5654
#
55+
# AppConfiguration.google_api_key # => "123456789"
5756
# AppConfiguration.google_api_key = "overriding the api key!"
57+
# AppConfiguration.google_api_key # => "overriding the api key!"
5858
#
59-
# To opt out of the instance writer method, pass :instance_writer => false.
60-
# To opt out of the instance reader method, pass :instance_reader => false.
61-
# To opt out of both instance methods, pass :instance_accessor => false.
59+
# To opt out of the instance writer method, pass instance_writer: false.
60+
# To opt out of the instance reader method, pass instance_reader: false.
61+
# To opt out of both instance methods, pass instance_accessor: false.
6262
def mattr_accessor(*syms)
6363
mattr_reader(*syms)
6464
mattr_writer(*syms)

guides/source/security.textile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,17 @@ protect_from_forgery :secret => "123456789012345678901234567890..."
236236

237237
This will automatically include a security token, calculated from the current session and the server-side secret, in all forms and Ajax requests generated by Rails. You won't need the secret, if you use CookieStorage as session storage. If the security token doesn't match what was expected, the session will be reset. *Note:* In Rails versions prior to 3.0.4, this raised an <tt>ActionController::InvalidAuthenticityToken</tt> error.
238238

239+
It is common to use persistent cookies to store user information, with +cookies.permanent+ for example. In this case, the cookies will not be cleared and the out of the box CSRF protection will not be effective. If you are using a different cookie store than the session for this information, you must handle what to do with it yourself:
240+
241+
<ruby>
242+
def handle_unverified_request
243+
super
244+
sign_out_user # Example method that will destroy the user cookies.
245+
end
246+
</ruby>
247+
248+
The above method can be placed in the +ApplicationController+ and will be called when a CSRF token is not present on a non-GET request.
249+
239250
Note that _(highlight)cross-site scripting (XSS) vulnerabilities bypass all CSRF protections_. XSS gives the attacker access to all elements on a page, so he can read the CSRF security token from a form or directly submit the form. Read <a href="#cross-site-scripting-xss">more about XSS</a> later.
240251

241252
h3. Redirection and Files

0 commit comments

Comments
 (0)