mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge branch 'master' of git://github.com/lifo/docrails
Conflicts: activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
This commit is contained in:
commit
af1b48926f
17 changed files with 98 additions and 67 deletions
|
@ -268,7 +268,7 @@ module ActionView
|
||||||
# image_path("edit.png") # => "/images/edit.png"
|
# image_path("edit.png") # => "/images/edit.png"
|
||||||
# image_path("icons/edit.png") # => "/images/icons/edit.png"
|
# image_path("icons/edit.png") # => "/images/icons/edit.png"
|
||||||
# image_path("/icons/edit.png") # => "/icons/edit.png"
|
# image_path("/icons/edit.png") # => "/icons/edit.png"
|
||||||
# image_path("http://www.railsapplication.com/img/edit.png") # => "http://www.railsapplication.com/img/edit.png"
|
# image_path("http://www.example.com/img/edit.png") # => "http://www.example.com/img/edit.png"
|
||||||
#
|
#
|
||||||
# If you have images as application resources this method may conflict with their named routes.
|
# If you have images as application resources this method may conflict with their named routes.
|
||||||
# The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
|
# The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
|
||||||
|
@ -291,7 +291,7 @@ module ActionView
|
||||||
# video_path("hd.avi") # => /videos/hd.avi
|
# video_path("hd.avi") # => /videos/hd.avi
|
||||||
# video_path("trailers/hd.avi") # => /videos/trailers/hd.avi
|
# video_path("trailers/hd.avi") # => /videos/trailers/hd.avi
|
||||||
# video_path("/trailers/hd.avi") # => /trailers/hd.avi
|
# video_path("/trailers/hd.avi") # => /trailers/hd.avi
|
||||||
# video_path("http://www.railsapplication.com/vid/hd.avi") # => http://www.railsapplication.com/vid/hd.avi
|
# video_path("http://www.example.com/vid/hd.avi") # => http://www.example.com/vid/hd.avi
|
||||||
def video_path(source)
|
def video_path(source)
|
||||||
if config.use_sprockets
|
if config.use_sprockets
|
||||||
asset_path(source)
|
asset_path(source)
|
||||||
|
@ -310,7 +310,7 @@ module ActionView
|
||||||
# audio_path("horse.wav") # => /audios/horse.wav
|
# audio_path("horse.wav") # => /audios/horse.wav
|
||||||
# audio_path("sounds/horse.wav") # => /audios/sounds/horse.wav
|
# audio_path("sounds/horse.wav") # => /audios/sounds/horse.wav
|
||||||
# audio_path("/sounds/horse.wav") # => /sounds/horse.wav
|
# audio_path("/sounds/horse.wav") # => /sounds/horse.wav
|
||||||
# audio_path("http://www.railsapplication.com/sounds/horse.wav") # => http://www.railsapplication.com/sounds/horse.wav
|
# audio_path("http://www.example.com/sounds/horse.wav") # => http://www.example.com/sounds/horse.wav
|
||||||
def audio_path(source)
|
def audio_path(source)
|
||||||
if config.use_sprockets
|
if config.use_sprockets
|
||||||
asset_path(source)
|
asset_path(source)
|
||||||
|
|
|
@ -77,11 +77,11 @@ module ActionView
|
||||||
# Used internally by javascript_include_tag to build the script path.
|
# Used internally by javascript_include_tag to build the script path.
|
||||||
#
|
#
|
||||||
# ==== Examples
|
# ==== Examples
|
||||||
# javascript_path "xmlhr" # => /javascripts/xmlhr.js
|
# javascript_path "xmlhr" # => /javascripts/xmlhr.js
|
||||||
# javascript_path "dir/xmlhr.js" # => /javascripts/dir/xmlhr.js
|
# javascript_path "dir/xmlhr.js" # => /javascripts/dir/xmlhr.js
|
||||||
# javascript_path "/dir/xmlhr" # => /dir/xmlhr.js
|
# javascript_path "/dir/xmlhr" # => /dir/xmlhr.js
|
||||||
# javascript_path "http://www.railsapplication.com/js/xmlhr" # => http://www.railsapplication.com/js/xmlhr
|
# javascript_path "http://www.example.com/js/xmlhr" # => http://www.example.com/js/xmlhr
|
||||||
# javascript_path "http://www.railsapplication.com/js/xmlhr.js" # => http://www.railsapplication.com/js/xmlhr.js
|
# javascript_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js
|
||||||
def javascript_path(source)
|
def javascript_path(source)
|
||||||
if config.use_sprockets
|
if config.use_sprockets
|
||||||
asset_path(source, 'js')
|
asset_path(source, 'js')
|
||||||
|
@ -123,11 +123,11 @@ module ActionView
|
||||||
# # => <script type="text/javascript" src="/javascripts/common.javascript?1284139606"></script>
|
# # => <script type="text/javascript" src="/javascripts/common.javascript?1284139606"></script>
|
||||||
# # <script type="text/javascript" src="/elsewhere/cools.js?1423139606"></script>
|
# # <script type="text/javascript" src="/elsewhere/cools.js?1423139606"></script>
|
||||||
#
|
#
|
||||||
# javascript_include_tag "http://www.railsapplication.com/xmlhr"
|
# javascript_include_tag "http://www.example.com/xmlhr"
|
||||||
# # => <script type="text/javascript" src="http://www.railsapplication.com/xmlhr.js?1284139606"></script>
|
# # => <script type="text/javascript" src="http://www.example.com/xmlhr.js?1284139606"></script>
|
||||||
#
|
#
|
||||||
# javascript_include_tag "http://www.railsapplication.com/xmlhr.js"
|
# javascript_include_tag "http://www.example.com/xmlhr.js"
|
||||||
# # => <script type="text/javascript" src="http://www.railsapplication.com/xmlhr.js?1284139606"></script>
|
# # => <script type="text/javascript" src="http://www.example.com/xmlhr.js?1284139606"></script>
|
||||||
#
|
#
|
||||||
# javascript_include_tag :defaults
|
# javascript_include_tag :defaults
|
||||||
# # => <script type="text/javascript" src="/javascripts/jquery.js?1284139606"></script>
|
# # => <script type="text/javascript" src="/javascripts/jquery.js?1284139606"></script>
|
||||||
|
|
|
@ -54,11 +54,11 @@ module ActionView
|
||||||
# Used internally by +stylesheet_link_tag+ to build the stylesheet path.
|
# Used internally by +stylesheet_link_tag+ to build the stylesheet path.
|
||||||
#
|
#
|
||||||
# ==== Examples
|
# ==== Examples
|
||||||
# stylesheet_path "style" # => /stylesheets/style.css
|
# stylesheet_path "style" # => /stylesheets/style.css
|
||||||
# stylesheet_path "dir/style.css" # => /stylesheets/dir/style.css
|
# stylesheet_path "dir/style.css" # => /stylesheets/dir/style.css
|
||||||
# stylesheet_path "/dir/style.css" # => /dir/style.css
|
# stylesheet_path "/dir/style.css" # => /dir/style.css
|
||||||
# stylesheet_path "http://www.railsapplication.com/css/style" # => http://www.railsapplication.com/css/style
|
# stylesheet_path "http://www.example.com/css/style" # => http://www.example.com/css/style
|
||||||
# stylesheet_path "http://www.railsapplication.com/css/style.css" # => http://www.railsapplication.com/css/style.css
|
# stylesheet_path "http://www.example.com/css/style.css" # => http://www.example.com/css/style.css
|
||||||
def stylesheet_path(source)
|
def stylesheet_path(source)
|
||||||
if config.use_sprockets
|
if config.use_sprockets
|
||||||
asset_path(source, 'css')
|
asset_path(source, 'css')
|
||||||
|
@ -79,8 +79,8 @@ module ActionView
|
||||||
# stylesheet_link_tag "style.css" # =>
|
# stylesheet_link_tag "style.css" # =>
|
||||||
# <link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />
|
# <link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />
|
||||||
#
|
#
|
||||||
# stylesheet_link_tag "http://www.railsapplication.com/style.css" # =>
|
# stylesheet_link_tag "http://www.example.com/style.css" # =>
|
||||||
# <link href="http://www.railsapplication.com/style.css" media="screen" rel="stylesheet" type="text/css" />
|
# <link href="http://www.example.com/style.css" media="screen" rel="stylesheet" type="text/css" />
|
||||||
#
|
#
|
||||||
# stylesheet_link_tag "style", :media => "all" # =>
|
# stylesheet_link_tag "style", :media => "all" # =>
|
||||||
# <link href="/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />
|
# <link href="/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />
|
||||||
|
|
|
@ -10,7 +10,7 @@ module ActionView
|
||||||
# relate to the specified Active Record object. Usage example:
|
# relate to the specified Active Record object. Usage example:
|
||||||
#
|
#
|
||||||
# <%= div_for(@person, :class => "foo") do %>
|
# <%= div_for(@person, :class => "foo") do %>
|
||||||
# <%=h @person.name %>
|
# <%= @person.name %>
|
||||||
# <% end %>
|
# <% end %>
|
||||||
#
|
#
|
||||||
# produces:
|
# produces:
|
||||||
|
@ -25,8 +25,8 @@ module ActionView
|
||||||
# that relate to the specified Active Record object. For example:
|
# that relate to the specified Active Record object. For example:
|
||||||
#
|
#
|
||||||
# <%= content_tag_for(:tr, @person) do %>
|
# <%= content_tag_for(:tr, @person) do %>
|
||||||
# <td><%=h @person.first_name %></td>
|
# <td><%= @person.first_name %></td>
|
||||||
# <td><%=h @person.last_name %></td>
|
# <td><%= @person.last_name %></td>
|
||||||
# <% end %>
|
# <% end %>
|
||||||
#
|
#
|
||||||
# would produce the following HTML (assuming @person is an instance of
|
# would produce the following HTML (assuming @person is an instance of
|
||||||
|
|
|
@ -68,7 +68,7 @@ module ActionView
|
||||||
# # => /books/find
|
# # => /books/find
|
||||||
#
|
#
|
||||||
# <%= url_for(:action => 'login', :controller => 'members', :only_path => false, :protocol => 'https') %>
|
# <%= url_for(:action => 'login', :controller => 'members', :only_path => false, :protocol => 'https') %>
|
||||||
# # => https://www.railsapplication.com/members/login/
|
# # => https://www.example.com/members/login/
|
||||||
#
|
#
|
||||||
# <%= url_for(:action => 'play', :anchor => 'player') %>
|
# <%= url_for(:action => 'play', :anchor => 'player') %>
|
||||||
# # => /messages/play/#player
|
# # => /messages/play/#player
|
||||||
|
|
|
@ -69,10 +69,10 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||||
assert_equal "/dir/xmlhr.js",
|
assert_equal "/dir/xmlhr.js",
|
||||||
asset_path("/dir/xmlhr", "js")
|
asset_path("/dir/xmlhr", "js")
|
||||||
|
|
||||||
assert_equal "http://www.railsapplication.com/js/xmlhr",
|
assert_equal "http://www.example.com/js/xmlhr",
|
||||||
asset_path("http://www.railsapplication.com/js/xmlhr", "js")
|
asset_path("http://www.example.com/js/xmlhr", "js")
|
||||||
assert_equal "http://www.railsapplication.com/js/xmlhr.js",
|
assert_equal "http://www.example.com/js/xmlhr.js",
|
||||||
asset_path("http://www.railsapplication.com/js/xmlhr.js", "js")
|
asset_path("http://www.example.com/js/xmlhr.js", "js")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "javascript include tag" do
|
test "javascript include tag" do
|
||||||
|
@ -83,8 +83,8 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||||
sprockets_javascript_include_tag("xmlhr")
|
sprockets_javascript_include_tag("xmlhr")
|
||||||
assert_equal '<script src="/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
|
assert_equal '<script src="/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
|
||||||
sprockets_javascript_include_tag("xmlhr.js")
|
sprockets_javascript_include_tag("xmlhr.js")
|
||||||
assert_equal '<script src="http://www.railsapplication.com/xmlhr" type="text/javascript"></script>',
|
assert_equal '<script src="http://www.example.com/xmlhr" type="text/javascript"></script>',
|
||||||
sprockets_javascript_include_tag("http://www.railsapplication.com/xmlhr")
|
sprockets_javascript_include_tag("http://www.example.com/xmlhr")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "stylesheet path" do
|
test "stylesheet path" do
|
||||||
|
@ -94,10 +94,10 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||||
assert_equal "/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("dir/style.css", "css")
|
assert_equal "/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("dir/style.css", "css")
|
||||||
assert_equal "/dir/style.css", asset_path("/dir/style.css", "css")
|
assert_equal "/dir/style.css", asset_path("/dir/style.css", "css")
|
||||||
|
|
||||||
assert_equal "http://www.railsapplication.com/css/style",
|
assert_equal "http://www.example.com/css/style",
|
||||||
asset_path("http://www.railsapplication.com/css/style", "css")
|
asset_path("http://www.example.com/css/style", "css")
|
||||||
assert_equal "http://www.railsapplication.com/css/style.css",
|
assert_equal "http://www.example.com/css/style.css",
|
||||||
asset_path("http://www.railsapplication.com/css/style.css", "css")
|
asset_path("http://www.example.com/css/style.css", "css")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "stylesheet link tag" do
|
test "stylesheet link tag" do
|
||||||
|
@ -109,8 +109,8 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||||
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
|
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
|
||||||
sprockets_stylesheet_link_tag("style.css")
|
sprockets_stylesheet_link_tag("style.css")
|
||||||
|
|
||||||
assert_equal '<link href="http://www.railsapplication.com/style.css" media="screen" rel="stylesheet" type="text/css" />',
|
assert_equal '<link href="http://www.example.com/style.css" media="screen" rel="stylesheet" type="text/css" />',
|
||||||
sprockets_stylesheet_link_tag("http://www.railsapplication.com/style.css")
|
sprockets_stylesheet_link_tag("http://www.example.com/style.css")
|
||||||
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="all" rel="stylesheet" type="text/css" />',
|
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="all" rel="stylesheet" type="text/css" />',
|
||||||
sprockets_stylesheet_link_tag("style", :media => "all")
|
sprockets_stylesheet_link_tag("style", :media => "all")
|
||||||
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="print" rel="stylesheet" type="text/css" />',
|
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="print" rel="stylesheet" type="text/css" />',
|
||||||
|
|
|
@ -43,7 +43,7 @@ module ActiveModel
|
||||||
@observer_instances ||= []
|
@observer_instances ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
# Instantiate the global Active Record observers.
|
# Instantiate the global observers.
|
||||||
def instantiate_observers
|
def instantiate_observers
|
||||||
observers.each { |o| instantiate_observer(o) }
|
observers.each { |o| instantiate_observer(o) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -208,16 +208,18 @@ module ActiveRecord
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns +true+ when the connection adapter supports prepared statement
|
# Returns +true+, since this connection adapter supports prepared statement
|
||||||
# caching, otherwise returns +false+
|
# caching.
|
||||||
def supports_statement_cache?
|
def supports_statement_cache?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns true.
|
||||||
def supports_migrations? #:nodoc:
|
def supports_migrations? #:nodoc:
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns true.
|
||||||
def supports_primary_key? #:nodoc:
|
def supports_primary_key? #:nodoc:
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -308,6 +310,8 @@ module ActiveRecord
|
||||||
connect
|
connect
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Disconnects from the database if already connected. Otherwise, this
|
||||||
|
# method does nothing.
|
||||||
def disconnect!
|
def disconnect!
|
||||||
@connection.close rescue nil
|
@connection.close rescue nil
|
||||||
end
|
end
|
||||||
|
@ -330,6 +334,7 @@ module ActiveRecord
|
||||||
rows
|
rows
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Clears the prepared statements cache.
|
||||||
def clear_cache!
|
def clear_cache!
|
||||||
@statements.values.each do |cache|
|
@statements.values.each do |cache|
|
||||||
cache[:stmt].close
|
cache[:stmt].close
|
||||||
|
@ -554,6 +559,10 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Drops a MySQL database.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# drop_database 'sebastian_development'
|
||||||
def drop_database(name) #:nodoc:
|
def drop_database(name) #:nodoc:
|
||||||
execute "DROP DATABASE IF EXISTS `#{name}`"
|
execute "DROP DATABASE IF EXISTS `#{name}`"
|
||||||
end
|
end
|
||||||
|
|
|
@ -214,8 +214,8 @@ module ActiveRecord
|
||||||
ADAPTER_NAME
|
ADAPTER_NAME
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns +true+ when the connection adapter supports prepared statement
|
# Returns +true+, since this connection adapter supports prepared statement
|
||||||
# caching, otherwise returns +false+
|
# caching.
|
||||||
def supports_statement_cache?
|
def supports_statement_cache?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -240,6 +240,7 @@ module ActiveRecord
|
||||||
@local_tz = execute('SHOW TIME ZONE', 'SCHEMA').first["TimeZone"]
|
@local_tz = execute('SHOW TIME ZONE', 'SCHEMA').first["TimeZone"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Clears the prepared statements cache.
|
||||||
def clear_cache!
|
def clear_cache!
|
||||||
@statements.each_value do |value|
|
@statements.each_value do |value|
|
||||||
@connection.query "DEALLOCATE #{value}"
|
@connection.query "DEALLOCATE #{value}"
|
||||||
|
@ -278,7 +279,8 @@ module ActiveRecord
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
# Close the connection.
|
# Disconnects from the database if already connected. Otherwise, this
|
||||||
|
# method does nothing.
|
||||||
def disconnect!
|
def disconnect!
|
||||||
clear_cache!
|
clear_cache!
|
||||||
@connection.close rescue nil
|
@connection.close rescue nil
|
||||||
|
@ -641,7 +643,7 @@ module ActiveRecord
|
||||||
execute "CREATE DATABASE #{quote_table_name(name)}#{option_string}"
|
execute "CREATE DATABASE #{quote_table_name(name)}#{option_string}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Drops a PostgreSQL database
|
# Drops a PostgreSQL database.
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
# drop_database 'matt_development'
|
# drop_database 'matt_development'
|
||||||
|
|
|
@ -66,16 +66,18 @@ module ActiveRecord
|
||||||
sqlite_version >= '3.6.8'
|
sqlite_version >= '3.6.8'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns +true+ when the connection adapter supports prepared statement
|
# Returns true, since this connection adapter supports prepared statement
|
||||||
# caching, otherwise returns +false+
|
# caching.
|
||||||
def supports_statement_cache?
|
def supports_statement_cache?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns true.
|
||||||
def supports_migrations? #:nodoc:
|
def supports_migrations? #:nodoc:
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns true.
|
||||||
def supports_primary_key? #:nodoc:
|
def supports_primary_key? #:nodoc:
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -88,12 +90,15 @@ module ActiveRecord
|
||||||
sqlite_version >= '3.1.6'
|
sqlite_version >= '3.1.6'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Disconnects from the database if already connected. Otherwise, this
|
||||||
|
# method does nothing.
|
||||||
def disconnect!
|
def disconnect!
|
||||||
super
|
super
|
||||||
clear_cache!
|
clear_cache!
|
||||||
@connection.close rescue nil
|
@connection.close rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Clears the prepared statements cache.
|
||||||
def clear_cache!
|
def clear_cache!
|
||||||
@statements.clear
|
@statements.clear
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
class Object
|
class Object
|
||||||
# Returns true if this object is included in the argument. Argument must be
|
# Returns true if this object is included in the argument. Argument must be
|
||||||
# any object which respond to +#include?+. Usage:
|
# any object which responds to +#include?+. Usage:
|
||||||
#
|
#
|
||||||
# characters = ["Konata", "Kagami", "Tsukasa"]
|
# characters = ["Konata", "Kagami", "Tsukasa"]
|
||||||
# "Konata".in?(characters) # => true
|
# "Konata".in?(characters) # => true
|
||||||
#
|
#
|
||||||
# This will throw an ArgumentError if the supplied argument doesnt not respond
|
# This will throw an ArgumentError if the argument doesn't respond
|
||||||
# to +#include?+.
|
# to +#include?+.
|
||||||
def in?(another_object)
|
def in?(another_object)
|
||||||
another_object.include?(self)
|
another_object.include?(self)
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Object
|
||||||
end
|
end
|
||||||
|
|
||||||
class NilClass
|
class NilClass
|
||||||
# Instances of +NilClass+ return always +nil+.
|
# Calling +try+ on +nil+ always returns +nil+.
|
||||||
# It becomes specially helpful when navigating through associations that may return +nil+.
|
# It becomes specially helpful when navigating through associations that may return +nil+.
|
||||||
#
|
#
|
||||||
# === Examples
|
# === Examples
|
||||||
|
|
|
@ -418,7 +418,7 @@ SELECT viewable_by, locked FROM clients
|
||||||
Be careful because this also means you're initializing a model object with only the fields that you've selected. If you attempt to access a field that is not in the initialized record you'll receive:
|
Be careful because this also means you're initializing a model object with only the fields that you've selected. If you attempt to access a field that is not in the initialized record you'll receive:
|
||||||
|
|
||||||
<shell>
|
<shell>
|
||||||
ActiveRecord::MissingAttributeError: missing attribute: <attribute>
|
ActiveModel::MissingAttributeError: missing attribute: <attribute>
|
||||||
</shell>
|
</shell>
|
||||||
|
|
||||||
Where +<attribute>+ is the attribute you asked for. The +id+ method will not raise the +ActiveRecord::MissingAttributeError+, so just be careful when working with associations because they need the +id+ method to function properly.
|
Where +<attribute>+ is the attribute you asked for. The +id+ method will not raise the +ActiveRecord::MissingAttributeError+, so just be careful when working with associations because they need the +id+ method to function properly.
|
||||||
|
|
|
@ -897,8 +897,9 @@ The macro-style class methods can also receive a block. Consider using this styl
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
validates_presence_of :login, :email
|
validates_presence_of :login, :email
|
||||||
|
|
||||||
before_create {|user| user.name = user.login.capitalize
|
before_create do |user|
|
||||||
if user.name.blank?}
|
user.name = user.login.capitalize if user.name.blank?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
</ruby>
|
</ruby>
|
||||||
|
|
||||||
|
|
|
@ -1266,6 +1266,15 @@ WARNING: The option +:separator+ can't be a regexp.
|
||||||
|
|
||||||
NOTE: Defined in +active_support/core_ext/string/filters.rb+.
|
NOTE: Defined in +active_support/core_ext/string/filters.rb+.
|
||||||
|
|
||||||
|
h4. +inquiry+
|
||||||
|
|
||||||
|
The <tt>inquiry</tt> method converts a string into a +StringInquirer+ object making equality checks prettier.
|
||||||
|
|
||||||
|
<ruby>
|
||||||
|
"production".inquiry.production? # => true
|
||||||
|
"active".inquiry.inactive? # => false
|
||||||
|
</ruby>
|
||||||
|
|
||||||
h4. Key-based Interpolation
|
h4. Key-based Interpolation
|
||||||
|
|
||||||
In Ruby 1.9 the <tt>%</tt> string operator supports key-based interpolation, both formatted and unformatted:
|
In Ruby 1.9 the <tt>%</tt> string operator supports key-based interpolation, both formatted and unformatted:
|
||||||
|
@ -1997,6 +2006,11 @@ Similarly, +from+ returns the tail from the element at the passed index on:
|
||||||
|
|
||||||
The methods +second+, +third+, +fourth+, and +fifth+ return the corresponding element (+first+ is built-in). Thanks to social wisdom and positive constructiveness all around, +forty_two+ is also available.
|
The methods +second+, +third+, +fourth+, and +fifth+ return the corresponding element (+first+ is built-in). Thanks to social wisdom and positive constructiveness all around, +forty_two+ is also available.
|
||||||
|
|
||||||
|
<ruby>
|
||||||
|
%w(a b c d).third # => c
|
||||||
|
%w(a b c d).fifth # => nil
|
||||||
|
</ruby>
|
||||||
|
|
||||||
NOTE: Defined in +active_support/core_ext/array/access.rb+.
|
NOTE: Defined in +active_support/core_ext/array/access.rb+.
|
||||||
|
|
||||||
h4. Random Access
|
h4. Random Access
|
||||||
|
@ -2092,7 +2106,7 @@ h5. +to_xml+
|
||||||
The method +to_xml+ returns a string containing an XML representation of its receiver:
|
The method +to_xml+ returns a string containing an XML representation of its receiver:
|
||||||
|
|
||||||
<ruby>
|
<ruby>
|
||||||
Contributor.all(:limit => 2, :order => 'rank ASC').to_xml
|
Contributor.limit(2).order(:rank).to_xml
|
||||||
# =>
|
# =>
|
||||||
# <?xml version="1.0" encoding="UTF-8"?>
|
# <?xml version="1.0" encoding="UTF-8"?>
|
||||||
# <contributors type="array">
|
# <contributors type="array">
|
||||||
|
@ -2167,7 +2181,7 @@ The name of children nodes is by default the name of the root node singularized.
|
||||||
The default XML builder is a fresh instance of <tt>Builder::XmlMarkup</tt>. You can configure your own builder via the <tt>:builder</tt> option. The method also accepts options like <tt>:dasherize</tt> and friends, they are forwarded to the builder:
|
The default XML builder is a fresh instance of <tt>Builder::XmlMarkup</tt>. You can configure your own builder via the <tt>:builder</tt> option. The method also accepts options like <tt>:dasherize</tt> and friends, they are forwarded to the builder:
|
||||||
|
|
||||||
<ruby>
|
<ruby>
|
||||||
Contributor.all(:limit => 2, :order => 'rank ASC').to_xml(:skip_types => true)
|
Contributor.limit(2).order(:rank).to_xml(:skip_types => true)
|
||||||
# =>
|
# =>
|
||||||
# <?xml version="1.0" encoding="UTF-8"?>
|
# <?xml version="1.0" encoding="UTF-8"?>
|
||||||
# <contributors>
|
# <contributors>
|
||||||
|
@ -3407,11 +3421,11 @@ h4. +silence+
|
||||||
Silences every log level lesser to the specified one for the duration of the given block. Log level orders are: debug, info, error and fatal.
|
Silences every log level lesser to the specified one for the duration of the given block. Log level orders are: debug, info, error and fatal.
|
||||||
|
|
||||||
<ruby>
|
<ruby>
|
||||||
logger = Logger.new("log/development.log")
|
logger = Logger.new("log/development.log")
|
||||||
logger.silence(Logger::INFO) do
|
logger.silence(Logger::INFO) do
|
||||||
logger.debug("In space, no one can hear you scream.")
|
logger.debug("In space, no one can hear you scream.")
|
||||||
logger.info("Scream all you want, small mailman!")
|
logger.info("Scream all you want, small mailman!")
|
||||||
end
|
end
|
||||||
</ruby>
|
</ruby>
|
||||||
|
|
||||||
h4. +datetime_format=+
|
h4. +datetime_format=+
|
||||||
|
@ -3419,17 +3433,17 @@ h4. +datetime_format=+
|
||||||
Modifies the datetime format output by the formatter class associated with this logger. If the formatter class does not have a +datetime_format+ method then this is ignored.
|
Modifies the datetime format output by the formatter class associated with this logger. If the formatter class does not have a +datetime_format+ method then this is ignored.
|
||||||
|
|
||||||
<ruby>
|
<ruby>
|
||||||
class Logger::FormatWithTime < Logger::Formatter
|
class Logger::FormatWithTime < Logger::Formatter
|
||||||
cattr_accessor(:datetime_format) { "%Y%m%d%H%m%S" }
|
cattr_accessor(:datetime_format) { "%Y%m%d%H%m%S" }
|
||||||
|
|
||||||
def self.call(severity, timestamp, progname, msg)
|
def self.call(severity, timestamp, progname, msg)
|
||||||
"#{timestamp.strftime(datetime_format)} -- #{String === msg ? msg : msg.inspect}\n"
|
"#{timestamp.strftime(datetime_format)} -- #{String === msg ? msg : msg.inspect}\n"
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
logger = Logger.new("log/development.log")
|
logger = Logger.new("log/development.log")
|
||||||
logger.formatter = Logger::FormatWithTime
|
logger.formatter = Logger::FormatWithTime
|
||||||
logger.info("<- is the current time")
|
logger.info("<- is the current time")
|
||||||
</ruby>
|
</ruby>
|
||||||
|
|
||||||
NOTE: Defined in +active_support/core_ext/logger.rb+.
|
NOTE: Defined in +active_support/core_ext/logger.rb+.
|
||||||
|
|
|
@ -557,7 +557,7 @@ match '*a/foo/*b' => 'test#index'
|
||||||
|
|
||||||
would match +zoo/woo/foo/bar/baz+ with +params[:a]+ equals +"zoo/woo"+, and +params[:b]+ equals +"bar/baz"+.
|
would match +zoo/woo/foo/bar/baz+ with +params[:a]+ equals +"zoo/woo"+, and +params[:b]+ equals +"bar/baz"+.
|
||||||
|
|
||||||
NOTE: Starting from Rails 3.1, wildcard route will always matching the optional format segment by default. For example if you have this route:
|
NOTE: Starting from Rails 3.1, wildcard routes will always match the optional format segment by default. For example if you have this route:
|
||||||
|
|
||||||
<ruby>
|
<ruby>
|
||||||
map '*pages' => 'pages#show'
|
map '*pages' => 'pages#show'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'generators/generators_test_helper'
|
require 'generators/generators_test_helper'
|
||||||
require 'rails/generators/rails/assets/assets_generator'
|
require 'rails/generators/rails/assets/assets_generator'
|
||||||
|
|
||||||
# FOXME: Silence the 'Could not find task "using_coffee?"' message in tests due to the public stub
|
# FIXME: Silence the 'Could not find task "using_coffee?"' message in tests due to the public stub
|
||||||
class AssetsGeneratorTest < Rails::Generators::TestCase
|
class AssetsGeneratorTest < Rails::Generators::TestCase
|
||||||
include GeneratorsTestHelper
|
include GeneratorsTestHelper
|
||||||
arguments %w(posts)
|
arguments %w(posts)
|
||||||
|
|
Loading…
Reference in a new issue