Merge branch 'master' of github.com:rails/docrails

This commit is contained in:
Vijay Dev 2014-03-29 17:08:40 +05:30
commit 3ae33961e0
4 changed files with 20 additions and 2 deletions

@ -357,6 +357,10 @@ def root(options = {})
# # params[:category] = 'rock/classic' # # params[:category] = 'rock/classic'
# # params[:title] = 'stairway-to-heaven' # # params[:title] = 'stairway-to-heaven'
# #
# To match a wildcard parameter, it must have a name assigned to it.
# Without a variable name to attach the glob parameter to, the route
# can't be parsed.
#
# When a pattern points to an internal route, the route's +:action+ and # When a pattern points to an internal route, the route's +:action+ and
# +:controller+ should be set in options or hash shorthand. Examples: # +:controller+ should be set in options or hash shorthand. Examples:
# #

@ -170,7 +170,7 @@ def preload!(*args) # :nodoc:
# Use to indicate that the given +table_names+ are referenced by an SQL string, # Use to indicate that the given +table_names+ are referenced by an SQL string,
# and should therefore be JOINed in any query rather than loaded separately. # and should therefore be JOINed in any query rather than loaded separately.
# This method only works in conjuction with +includes+. # This method only works in conjunction with +includes+.
# See #includes for more details. # See #includes for more details.
# #
# User.includes(:posts).where("posts.name = 'foo'") # User.includes(:posts).where("posts.name = 'foo'")
@ -263,6 +263,10 @@ def select!(*fields) # :nodoc:
# #
# User.group('name AS grouped_name, age') # User.group('name AS grouped_name, age')
# => [#<User id: 3, name: "Foo", age: 21, ...>, #<User id: 2, name: "Oscar", age: 21, ...>, #<User id: 5, name: "Foo", age: 23, ...>] # => [#<User id: 3, name: "Foo", age: 21, ...>, #<User id: 2, name: "Oscar", age: 21, ...>, #<User id: 5, name: "Foo", age: 23, ...>]
#
# Passing in an array of attributes to group by is also supported.
# User.select([:id, :first_name]).group(:id, :first_name).first(3)
# => [#<User id: 1, first_name: "Bill">, #<User id: 2, first_name: "Earl">, #<User id: 3, first_name: "Beto">]
def group(*args) def group(*args)
check_if_method_has_arguments!(:group, args) check_if_method_has_arguments!(:group, args)
spawn.group!(*args) spawn.group!(*args)

@ -123,7 +123,7 @@ config.logger = Logger.new(STDOUT)
config.logger = Log4r::Logger.new("Application Log") config.logger = Log4r::Logger.new("Application Log")
``` ```
TIP: By default, each log is created under `Rails.root/log/` and the log file name is `environment_name.log`. TIP: By default, each log is created under `Rails.root/log/` and the log file is named after the environment in which the application is running.
### Log Levels ### Log Levels

@ -474,6 +474,16 @@ As with other helpers, if you were to use the `select` helper on a form builder
<%= f.select(:city_id, ...) %> <%= f.select(:city_id, ...) %>
``` ```
You can also pass a block to `select` helper:
```erb
<%= f.select(:city_id) do %>
<% [['Lisbon', 1], ['Madrid', 2]].each do |c| -%>
<%= content_tag(:option, c.first, value: c.last) %>
<% end %>
<% end %>
```
WARNING: If you are using `select` (or similar helpers such as `collection_select`, `select_tag`) to set a `belongs_to` association you must pass the name of the foreign key (in the example above `city_id`), not the name of association itself. If you specify `city` instead of `city_id` Active Record will raise an error along the lines of ` ActiveRecord::AssociationTypeMismatch: City(#17815740) expected, got String(#1138750) ` when you pass the `params` hash to `Person.new` or `update`. Another way of looking at this is that form helpers only edit attributes. You should also be aware of the potential security ramifications of allowing users to edit foreign keys directly. WARNING: If you are using `select` (or similar helpers such as `collection_select`, `select_tag`) to set a `belongs_to` association you must pass the name of the foreign key (in the example above `city_id`), not the name of association itself. If you specify `city` instead of `city_id` Active Record will raise an error along the lines of ` ActiveRecord::AssociationTypeMismatch: City(#17815740) expected, got String(#1138750) ` when you pass the `params` hash to `Person.new` or `update`. Another way of looking at this is that form helpers only edit attributes. You should also be aware of the potential security ramifications of allowing users to edit foreign keys directly.
### Option Tags from a Collection of Arbitrary Objects ### Option Tags from a Collection of Arbitrary Objects