diff options
author | Yehuda Katz <wycats@gmail.com> | 2009-07-19 23:24:19 +0900 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-07-19 23:24:19 +0900 |
commit | 45d41d8012c605f21de51e7018fa31e1d07776eb (patch) | |
tree | 21afefe5df997ee6abd3a62c0db4185bd7968bb6 /activemodel | |
parent | b20d68446d2fe98d129385a17a3a4cdacd4b5025 (diff) | |
download | rails-45d41d8012c605f21de51e7018fa31e1d07776eb.tar.gz rails-45d41d8012c605f21de51e7018fa31e1d07776eb.tar.bz2 rails-45d41d8012c605f21de51e7018fa31e1d07776eb.zip |
Add some simple examples for unconventional AMo and AP use
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/examples/amo_ap_example.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/activemodel/examples/amo_ap_example.rb b/activemodel/examples/amo_ap_example.rb new file mode 100644 index 0000000000..cef718d0d4 --- /dev/null +++ b/activemodel/examples/amo_ap_example.rb @@ -0,0 +1,36 @@ +$:.push "activesupport/lib" +$:.push "activemodel/lib" + +require "active_model/validations" +require "active_model/deprecated_error_methods" +require "active_model/errors" +require "active_model/naming" + +class Person + include ActiveModel::Validations + extend ActiveModel::Naming + + validates_presence_of :name + + attr_accessor :name + def initialize(attributes = {}) + @name = attributes[:name] + end + + def persist + @persisted = true + end + + def new_record? + @persisted + end + + def to_model() self end +end + +person1 = Person.new +p person1.valid? +person1.errors + +person2 = Person.new(:name => "matz") +p person2.valid?
\ No newline at end of file |