From a48f8089aba974465ccd1f99506f04d1f60ac2d2 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Wed, 20 Apr 2011 10:43:35 -0400 Subject: Exception got moved to ActiveModel with Rails 3 --- railties/guides/source/active_record_querying.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 7cdffe4c2e..2f0a51e868 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -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: -ActiveRecord::MissingAttributeError: missing attribute: +ActiveModel::MissingAttributeError: missing attribute: 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. -- cgit v1.2.3 From 2f0dca5ee081f22d20457150b92225958b6ef363 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 20 Apr 2011 23:25:33 +0530 Subject: document the Active Support extension - String#inquiry --- railties/guides/source/active_support_core_extensions.textile | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index b7f842a0d0..d4dda88937 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1266,6 +1266,15 @@ WARNING: The option +:separator+ can't be a regexp. NOTE: Defined in +active_support/core_ext/string/filters.rb+. +h4. +inquiry+ + +The String#inquiry method converts a string into a +StringInquirer+ object making equality checks prettier. + + +"production".inquiry.production? # => true +"active".inquiry.inactive? # => false + + h4. Key-based Interpolation In Ruby 1.9 the % string operator supports key-based interpolation, both formatted and unformatted: -- cgit v1.2.3 From eac264d74754eee6f157a75e386031ccbccd4328 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 23 Apr 2011 02:42:22 +0530 Subject: updating to_xml example to new AR api --- railties/guides/source/active_support_core_extensions.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index d4dda88937..4d5baff86b 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -2101,7 +2101,7 @@ h5. +to_xml+ The method +to_xml+ returns a string containing an XML representation of its receiver: -Contributor.all(:limit => 2, :order => 'rank ASC').to_xml +Contributor.limit(2).order(:rank).to_xml # => # # @@ -2176,7 +2176,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 Builder::XmlMarkup. You can configure your own builder via the :builder option. The method also accepts options like :dasherize and friends, they are forwarded to the builder: -Contributor.all(:limit => 2, :order => 'rank ASC').to_xml(:skip_types => true) +Contributor.limit(2).order(:rank).to_xml(:skip_types => true) # => # # -- cgit v1.2.3 From 98b700e0bfe836c7ee4754344202dd15c7ee0f2c Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 23 Apr 2011 02:45:29 +0530 Subject: add examples for array access methods --- railties/guides/source/active_support_core_extensions.textile | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 4d5baff86b..c937da834c 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -2006,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. + +%w(a b c d).third # => c +%w(a b c d).fifth # => nil + + NOTE: Defined in +active_support/core_ext/array/access.rb+. h4. Random Access -- cgit v1.2.3 From b22f39ec6f887725dd2780032a9a5be10217b7cb Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 23 Apr 2011 02:53:30 +0530 Subject: fix indentation --- .../source/active_support_core_extensions.textile | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index c937da834c..b57adbb517 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -3421,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. - logger = Logger.new("log/development.log") - logger.silence(Logger::INFO) do - logger.debug("In space, no one can hear you scream.") - logger.info("Scream all you want, small mailman!") - end +logger = Logger.new("log/development.log") +logger.silence(Logger::INFO) do + logger.debug("In space, no one can hear you scream.") + logger.info("Scream all you want, small mailman!") +end h4. +datetime_format=+ @@ -3433,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. - class Logger::FormatWithTime < Logger::Formatter - cattr_accessor(:datetime_format) { "%Y%m%d%H%m%S" } +class Logger::FormatWithTime < Logger::Formatter + cattr_accessor(:datetime_format) { "%Y%m%d%H%m%S" } - def self.call(severity, timestamp, progname, msg) - "#{timestamp.strftime(datetime_format)} -- #{String === msg ? msg : msg.inspect}\n" - end + def self.call(severity, timestamp, progname, msg) + "#{timestamp.strftime(datetime_format)} -- #{String === msg ? msg : msg.inspect}\n" end +end - logger = Logger.new("log/development.log") - logger.formatter = Logger::FormatWithTime - logger.info("<- is the current time") +logger = Logger.new("log/development.log") +logger.formatter = Logger::FormatWithTime +logger.info("<- is the current time") NOTE: Defined in +active_support/core_ext/logger.rb+. -- cgit v1.2.3 From e46e106c547054d4c6a898012e78b6ccfc835254 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 23 Apr 2011 03:06:06 +0530 Subject: fix block alignment --- railties/guides/source/active_record_validations_callbacks.textile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 9aab4b6694..19bd4ad0f1 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -897,8 +897,9 @@ The macro-style class methods can also receive a block. Consider using this styl class User < ActiveRecord::Base validates_presence_of :login, :email - before_create {|user| user.name = user.login.capitalize - if user.name.blank?} + before_create do |user| + user.name = user.login.capitalize if user.name.blank? + end end -- cgit v1.2.3 From 3050497a546396f273adfa5cd19330a8b2832931 Mon Sep 17 00:00:00 2001 From: Ronnie Miller Date: Fri, 22 Apr 2011 14:50:52 -0700 Subject: Grammer fix on note about wildcard routes --- railties/guides/source/routing.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 95b877aecf..43c08165dc 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -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"+. -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: map '*pages' => 'pages#show' -- cgit v1.2.3 From ec33de5dcb1df9b5123412820dd8ac1d9d6be992 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 23 Apr 2011 00:43:58 +0200 Subject: copy-edits 2f0dca5 --- railties/guides/source/active_support_core_extensions.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index b57adbb517..f89c83e4cd 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1268,7 +1268,7 @@ NOTE: Defined in +active_support/core_ext/string/filters.rb+. h4. +inquiry+ -The String#inquiry method converts a string into a +StringInquirer+ object making equality checks prettier. +The inquiry method converts a string into a +StringInquirer+ object making equality checks prettier. "production".inquiry.production? # => true -- cgit v1.2.3