From 021a101274b238f66a089c9c445f27df0918c9fc Mon Sep 17 00:00:00 2001 From: Aleksey Gureiev Date: Sat, 21 Jan 2012 20:23:14 +0200 Subject: Fixed typo in 'cast'. --- railties/guides/source/3_2_release_notes.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/3_2_release_notes.textile b/railties/guides/source/3_2_release_notes.textile index 74bc757948..d669a7fdfa 100644 --- a/railties/guides/source/3_2_release_notes.textile +++ b/railties/guides/source/3_2_release_notes.textile @@ -295,7 +295,7 @@ h4. Sprockets h3. Active Record -* Boolean columns with 'on' and 'ON' values are type casted to true. +* Boolean columns with 'on' and 'ON' values are type cast to true. * When the +timestamps+ method creates the +created_at+ and +updated_at+ columns, it makes them non-nullable by default. -- cgit v1.2.3 From b59e7b9ea33503d579facc95e94f00acdbfa2224 Mon Sep 17 00:00:00 2001 From: ciastek Date: Mon, 23 Jan 2012 00:58:40 +0100 Subject: "will be used throughout all the views for posts." could suggest, that code's modification is somehow related to posts, while it's application-wide --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index c77bc93cfb..db4b417536 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -853,7 +853,7 @@ below: Now when you refresh the +/posts+ page, you'll see a gray background to the -page. This same gray background will be used throughout all the views for posts. +page. This same gray background will be used throughout all the views for blog application. h4. Creating New Posts -- cgit v1.2.3 From 2bcfdec227077a7e693056e2a79470163402c2d5 Mon Sep 17 00:00:00 2001 From: ciastek Date: Mon, 23 Jan 2012 09:48:34 +0100 Subject: use CamelCase convention for "tag" model name --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index db4b417536..2860437310 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1668,7 +1668,7 @@ right in the form where you create the post. First, create a new model to hold the tags: -$ rails generate model tag name:string post:references +$ rails generate model Tag name:string post:references Again, run the migration to create the database table: -- cgit v1.2.3 From fce92fd8a7e407b034d189a652af81a06ac98730 Mon Sep 17 00:00:00 2001 From: leprasmurf Date: Mon, 23 Jan 2012 14:13:33 -0500 Subject: Added Apache configuration for dynamic gzip content --- railties/guides/source/asset_pipeline.textile | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index ff2bd08602..f6e56ed529 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -505,7 +505,30 @@ This directive is available if the core module that provides this feature was co If you're compiling nginx with Phusion Passenger you'll need to pass that option when prompted. -A robust configuration for Apache is possible but tricky; please Google around. (Or help update this Guide if you have a good example configuration for Apache.) +For Apache: + +Using the Apache config tricks found on the Crave DIY blog, the following rewrite rules check the client's header to see if gzip is supported, then checks the filesystem to ensure a gzipped version exists, finally serving the gzipped file and forcing a the appropriate type. + + +# Turn on the Rewrite engine +RewriteEngine On +# Check the client headers to see if they accept gzips +RewriteCond %{HTTP:Accept-Encoding} gzip +# Confirm the file exists in gzip format +RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.gz -f +# Rewrite url to us gzip file +RewriteRule (.*\.(js|css))$ $1\.gz [L] + +# If we've rewritten to a .css.gz file, force text/css + + ForceType text/css + + +# If we've rewritten to a .js.gz file, force application/x-javascript + + ForceType application/x-javascript + + h4. Live Compilation -- cgit v1.2.3 From cd9a3b055d1d0efc76fe3825689f106afef34516 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 25 Jan 2012 09:10:35 -0200 Subject: Fix custom validation methods section in AR validations and callbacks guide The methods validate_on_create and validate_on_update are not available anymore in Rails, this removes them from the guide and adds an example on how to use validate with the :on option. --- .../source/active_record_validations_callbacks.textile | 16 ++++++++++++++-- 1 file changed, 14 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 a27c292a4c..ac5ee0694c 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -614,7 +614,7 @@ As shown in the example, you can also combine standard validations with your own h4. Custom Methods -You can also create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names. +You can also create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using the +validate+ class method, passing in the symbols for the validation methods' names. You can pass more than one symbol for each class method and the respective validations will be run in the same order as they were registered. @@ -637,12 +637,24 @@ class Invoice < ActiveRecord::Base end +By default such validations will run every time you call +valid?+. It is also possible to control when to run these custom validations by giving an +:on+ option to the +validate+ method, with either: +:create+ or +:update+. + + +class Invoice < ActiveRecord::Base + validate :active_customer, :on => :create + + def active_customer + errors.add(:customer_id, "is not active") unless customer.active? + end +end + + You can even create your own validation helpers and reuse them in several different models. For example, an application that manages surveys may find it useful to express that a certain field corresponds to a set of choices: ActiveRecord::Base.class_eval do def self.validates_as_choice(attr_name, n, options={}) - validates attr_name, :inclusion => { {:in => 1..n}.merge(options) } + validates attr_name, :inclusion => { { :in => 1..n }.merge!(options) } end end -- cgit v1.2.3 From 84bd203b39b0905723fc8be38bc9fd24f618e252 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 25 Jan 2012 09:31:00 -0200 Subject: Change ActiveRecord::Errors to ActiveModel::Errors in guides Use ActiveModel::Errors in inflection example docs as well. Also fixes wrong information and link to locale file related to Errors#full_messages in I18n guide. --- railties/guides/source/active_record_validations_callbacks.textile | 2 +- railties/guides/source/active_resource_basics.textile | 2 +- railties/guides/source/i18n.textile | 6 +++--- 3 files changed, 5 insertions(+), 5 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 ac5ee0694c..844876a973 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -671,7 +671,7 @@ h3. Working with Validation Errors In addition to the +valid?+ and +invalid?+ methods covered earlier, Rails provides a number of methods for working with the +errors+ collection and inquiring about the validity of objects. -The following is a list of the most commonly used methods. Please refer to the +ActiveRecord::Errors+ documentation for a list of all the available methods. +The following is a list of the most commonly used methods. Please refer to the +ActiveModel::Errors+ documentation for a list of all the available methods. h4(#working_with_validation_errors-errors). +errors+ diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 851aac1a3f..37abb8a640 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -71,7 +71,7 @@ person.destroy h3. Validations -Module to support validation and errors with Active Resource objects. The module overrides Base#save to rescue ActiveResource::ResourceInvalid exceptions and parse the errors returned in the web service response. The module also adds an errors collection that mimics the interface of the errors provided by ActiveRecord::Errors. +Module to support validation and errors with Active Resource objects. The module overrides Base#save to rescue ActiveResource::ResourceInvalid exceptions and parse the errors returned in the web service response. The module also adds an errors collection that mimics the interface of the errors provided by ActiveModel::Errors. h4. Validating client side resources by overriding validation methods in base class diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 16ad35f345..25201888e7 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -819,13 +819,13 @@ h5. Action View Helper Methods * The +number_to_currency+, +number_with_precision+, +number_to_percentage+, +number_with_delimiter+, and +number_to_human_size+ helpers use the number format settings located in the "number":https://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L2 scope. -h5. Active Record Methods +h5. Active Model Methods * +model_name.human+ and +human_attribute_name+ use translations for model names and attribute names if available in the "activerecord.models":https://github.com/rails/rails/blob/master/activerecord/lib/active_record/locale/en.yml#L29 scope. They also support translations for inherited class names (e.g. for use with STI) as explained above in "Error message scopes". -* +ActiveRecord::Errors#generate_message+ (which is used by Active Record validations but may also be used manually) uses +model_name.human+ and +human_attribute_name+ (see above). It also translates the error message and supports translations for inherited class names as explained above in "Error message scopes". +* +ActiveModel::Errors#generate_message+ (which is used by Active Model validations but may also be used manually) uses +model_name.human+ and +human_attribute_name+ (see above). It also translates the error message and supports translations for inherited class names as explained above in "Error message scopes". -* +ActiveRecord::Errors#full_messages+ prepends the attribute name to the error message using a separator that will be looked up from "activerecord.errors.format.separator":https://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L91 (and which defaults to +' '+). +* +ActiveModel::Errors#full_messages+ prepends the attribute name to the error message using a separator that will be looked up from "errors.format":https://github.com/rails/rails/blob/master/activemodel/lib/active_model/locale/en.yml#L4 (and which defaults to +"%{attribute} %{message}"+). h5. Active Support Methods -- cgit v1.2.3 From 0186c5dcea332ef033a8142047cdea1d7fde5d07 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 25 Jan 2012 09:49:10 -0200 Subject: Improve field error proc example in validations guide --- .../guides/source/active_record_validations_callbacks.textile | 9 ++------- 1 file changed, 2 insertions(+), 7 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 844876a973..4b74fae94e 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -901,13 +901,8 @@ Below is a simple example where we change the Rails behavior to always display t ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| - if instance.error_message.kind_of?(Array) - %(#{html_tag}  - #{instance.error_message.join(',')}).html_safe - else - %(#{html_tag}  - #{instance.error_message}).html_safe - end + errors = Array(instance.error_message).join(',') + %(#{html_tag} #{errors}).html_safe end -- cgit v1.2.3 From b844bf6a65c4e8eb330f45ef7b8343bec657bab9 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 25 Jan 2012 09:57:46 -0200 Subject: Fix callbacks order for destroying an object in validations guide Also add around save to creating/updating callbacks order, and fix save example with no validation --- railties/guides/source/active_record_validations_callbacks.textile | 6 ++++-- 1 file changed, 4 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 4b74fae94e..15d24f9ac1 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -956,6 +956,7 @@ h4. Creating an Object * +before_validation+ * +after_validation+ * +before_save+ +* +around_save+ * +before_create+ * +around_create+ * +after_create+ @@ -966,6 +967,7 @@ h4. Updating an Object * +before_validation+ * +after_validation+ * +before_save+ +* +around_save+ * +before_update+ * +around_update+ * +after_update+ @@ -974,8 +976,8 @@ h4. Updating an Object h4. Destroying an Object * +before_destroy+ -* +after_destroy+ * +around_destroy+ +* +after_destroy+ WARNING. +after_save+ runs both on create and update, but always _after_ the more specific callbacks +after_create+ and +after_update+, no matter the order in which the macro calls were executed. @@ -1020,7 +1022,7 @@ The following methods trigger callbacks: * +increment!+ * +save+ * +save!+ -* +save(false)+ +* +save(:validate => false)+ * +toggle!+ * +update+ * +update_attribute+ -- cgit v1.2.3 From b32ebf0461d8c6eebe5142f4ad7f38a8484b436b Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 25 Jan 2012 23:57:33 +0530 Subject: minor text change [ci skip] --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 2860437310..bed14ef6a8 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -853,7 +853,7 @@ below: Now when you refresh the +/posts+ page, you'll see a gray background to the -page. This same gray background will be used throughout all the views for blog application. +page. This same gray background will be used throughout all the views. h4. Creating New Posts -- cgit v1.2.3 From 368f0fe2d359209e2475a90bc7ef859cd93cc0a3 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 25 Jan 2012 23:57:44 +0530 Subject: Revert "Added Apache configuration for dynamic gzip content" This reverts commit fce92fd8a7e407b034d189a652af81a06ac98730. Reason: We want any config that goes into the guides to be 100% right and I'm not entirely sure that this one is it. We already had a similar config that was removed in https://github.com/rails/rails/commit/b1c20e37eccdfab7bb94d34f249c5e49256b9980 --- railties/guides/source/asset_pipeline.textile | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index f6e56ed529..ff2bd08602 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -505,30 +505,7 @@ This directive is available if the core module that provides this feature was co If you're compiling nginx with Phusion Passenger you'll need to pass that option when prompted. -For Apache: - -Using the Apache config tricks found on the Crave DIY blog, the following rewrite rules check the client's header to see if gzip is supported, then checks the filesystem to ensure a gzipped version exists, finally serving the gzipped file and forcing a the appropriate type. - - -# Turn on the Rewrite engine -RewriteEngine On -# Check the client headers to see if they accept gzips -RewriteCond %{HTTP:Accept-Encoding} gzip -# Confirm the file exists in gzip format -RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.gz -f -# Rewrite url to us gzip file -RewriteRule (.*\.(js|css))$ $1\.gz [L] - -# If we've rewritten to a .css.gz file, force text/css - - ForceType text/css - - -# If we've rewritten to a .js.gz file, force application/x-javascript - - ForceType application/x-javascript - - +A robust configuration for Apache is possible but tricky; please Google around. (Or help update this Guide if you have a good example configuration for Apache.) h4. Live Compilation -- cgit v1.2.3