diff options
author | Mikel Lindsaar <raasdnil@gmail.com> | 2010-02-02 14:04:23 +1100 |
---|---|---|
committer | Mikel Lindsaar <raasdnil@gmail.com> | 2010-02-02 14:04:23 +1100 |
commit | 12681c2a71f6272aaa8e1fa7cc6b5df588c96b1a (patch) | |
tree | a7a7b097f59eaddc8cb209a1e83505843eab99fa /activemodel/README | |
parent | 535ae3b946b387af7eb6cb4bb4aed3d5cac1cf81 (diff) | |
parent | df8852d04d030330efcb86f16977b837473bf022 (diff) | |
download | rails-12681c2a71f6272aaa8e1fa7cc6b5df588c96b1a.tar.gz rails-12681c2a71f6272aaa8e1fa7cc6b5df588c96b1a.tar.bz2 rails-12681c2a71f6272aaa8e1fa7cc6b5df588c96b1a.zip |
Merge branch 'master' of git://github.com/rails/rails
Conflicts:
activemodel/README
activemodel/lib/active_model/errors.rb
activemodel/lib/active_model/serialization.rb
railties/guides/source/3_0_release_notes.textile
Diffstat (limited to 'activemodel/README')
-rw-r--r-- | activemodel/README | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/activemodel/README b/activemodel/README index cf103b8d6d..3945a6da06 100644 --- a/activemodel/README +++ b/activemodel/README @@ -1,13 +1,13 @@ = Active Model - defined interfaces for Rails - + Prior to Rails 3.0, if a plugin or gem developer wanted to be able to have an object interact with Action Pack helpers, it was required to either copy chunks of code from Rails, or monkey patch entire helpers to make them handle objects that did not look like Active Record. This generated code duplication and fragile applications that broke on upgrades. - + Active Model is a solution for this problem. - + Active Model provides a known set of interfaces that your objects can implement to then present a common interface to the Action Pack helpers. You can include functionality from the following modules: @@ -75,7 +75,7 @@ functionality from the following modules: person.name = 'robert' person.save person.previous_changes # => {'name' => ['bob, 'robert']} - + {Learn more}[link:classes/ActiveModel/Dirty.html] * Adding +errors+ support to your object @@ -84,22 +84,22 @@ functionality from the following modules: helpers seamlessly... class Person - + def initialize @errors = ActiveModel::Errors.new(self) end - + attr_accessor :name attr_reader :errors - + def validate! errors.add(:name, "can not be nil") if name == nil end - + def ErrorsPerson.human_attribute_name(attr, options = {}) "Name" end - + end ... gives you... @@ -153,19 +153,6 @@ functionality from the following modules: s.to_xml # => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<serial-person... {Learn more}[link:classes/ActiveModel/Serialization.html] - - -* Turning your object into a finite State Machine - - ActiveModel::StateMachine provides a clean way to include all the methods - you need to transform your object into a finite State Machine... - - light = TrafficLight.new - light.current_state #=> :red - light.change_color! #=> true - light.current_state #=> :green - - {Learn more}[link:classes/ActiveModel/StateMachine.html] * Integrating with Rail's internationalization (i18n) handling through ActiveModel::Translations... @@ -183,11 +170,13 @@ functionality from the following modules: attr_accessor :first_name, :last_name + validates_each :first_name, :last_name do |record, attr, value| record.errors.add attr, 'starts with z.' if value.to_s[0] == ?z end end + person = Person.new(:first_name => 'zoolander') person.valid? #=> false @@ -214,5 +203,3 @@ functionality from the following modules: p.valid? #=> true {Learn more}[link:classes/ActiveModel/Validator.html] - -
\ No newline at end of file |