aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb1
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb13
-rw-r--r--railties/guides/source/active_record_validations_callbacks.textile12
-rw-r--r--railties/guides/source/caching_with_rails.textile2
-rw-r--r--railties/guides/source/layouts_and_rendering.textile2
-rw-r--r--railties/guides/source/routing.textile8
6 files changed, 35 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
index 20372c5c18..ac31b636db 100644
--- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
+++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ -58,6 +58,7 @@ module ActiveRecord
end
time = time.in_time_zone rescue nil if time
write_attribute(:#{attr_name}, original_time)
+ #{attr_name}_will_change!
@attributes_cache["#{attr_name}"] = time
end
EOV
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index 4078b7eb0b..fb51925a38 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -625,6 +625,19 @@ class AttributeMethodsTest < ActiveRecord::TestCase
end
end
+ def test_time_zone_aware_attribute_saved
+ time_string_1 = "2012-02-20 10:00:00"
+ time_string_2 = "2012-02-20 09:00:00"
+
+ in_time_zone 1 do
+ record = @target.create(:written_on => '2012-02-20 10:00')
+
+ record.written_on = '2012-02-20 09:00'
+ record.save
+ assert_equal Time.zone.local(2012, 02, 20, 9), record.reload.written_on
+ end
+ end
+
def test_setting_time_zone_aware_attribute_to_blank_string_returns_nil
in_time_zone "Pacific Time (US & Canada)" do
record = @target.new
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 72ac8d2db9..349d02c1f6 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -517,6 +517,18 @@ class Person < ActiveRecord::Base
end
</ruby>
+h3. Strict Validations
+
+You can also specify validations to be strict and raise +ActiveModel::StrictValidationFailed+ when the object is invalid.
+
+<ruby>
+class Person < ActiveRecord::Base
+ validates :name, :presence => { :strict => true }
+end
+
+Person.new.valid? => ActiveModel::StrictValidationFailed: Name can't be blank
+</ruby>
+
h3. Conditional Validation
Sometimes it will make sense to validate an object just when a given predicate is satisfied. You can do that by using the +:if+ and +:unless+ options, which can take a symbol, a string or a +Proc+. You may use the +:if+ option when you want to specify when the validation *should* happen. If you want to specify when the validation *should not* happen, then you may use the +:unless+ option.
diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile
index 6419d32c13..e2c6c7a2a4 100644
--- a/railties/guides/source/caching_with_rails.textile
+++ b/railties/guides/source/caching_with_rails.textile
@@ -359,7 +359,7 @@ h4. ActiveSupport::Cache::NullStore
This cache store implementation is meant to be used only in development or test environments and it never stores anything. This can be very useful in development when you have code that interacts directly with +Rails.cache+, but caching may interfere with being able to see the results of code changes. With this cache store, all +fetch+ and +read+ operations will result in a miss.
<ruby>
-ActionController::Base.cache_store = :null
+ActionController::Base.cache_store = :null_store
</ruby>
h4. Custom Cache Stores
diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile
index be352cfe3d..4b4f9f3745 100644
--- a/railties/guides/source/layouts_and_rendering.textile
+++ b/railties/guides/source/layouts_and_rendering.textile
@@ -359,7 +359,7 @@ class ProductsController < ApplicationController
end
</ruby>
-With this declaration, all of the methods within +ProductsController+ will use +app/views/layouts/inventory.html.erb+ for their layout.
+With this declaration, all of the views rendered by the products controller will use +app/views/layouts/inventory.html.erb+ as their layout.
To assign a specific layout for the entire application, use a +layout+ declaration in your +ApplicationController+ class:
diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile
index df2bd9d0c9..42665114be 100644
--- a/railties/guides/source/routing.textile
+++ b/railties/guides/source/routing.textile
@@ -295,12 +295,18 @@ In this case, Rails will see that +@magazine+ is a +Magazine+ and +@ad+ is an +A
<%= link_to "Ad details", [@magazine, @ad] %>
</erb>
-If you wanted to link to just a magazine, you could leave out the +Array+:
+If you wanted to link to just a magazine:
<erb>
<%= link_to "Magazine details", @magazine %>
</erb>
+For other actions, you just need to insert the action name as the first element of the array:
+
+<erb>
+<%= link_to "Edit Ad", [:edit, @magazine, @ad] %>
+</erb>
+
This allows you to treat instances of your models as URLs, and is a key advantage to using the resourceful style.
h4. Adding More RESTful Actions