Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added examples for Rails3 ActiveModel validations and serialization [#…
…115]
- Loading branch information
1 parent
02eebb5
commit df5d745
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../../lib") | ||
|
||
require 'rubygems' | ||
require 'neo4j' | ||
require 'neo4j/extensions/activemodel' | ||
|
||
class Person | ||
include Neo4j::NodeMixin | ||
include ActiveModel::Serializers::JSON | ||
include ActiveModel::Serializers::Xml | ||
|
||
property :first_name | ||
property :last_name | ||
|
||
end | ||
|
||
|
||
Neo4j::Transaction.run do | ||
person = Person.new :first_name => 'jimmy', :last_name => 'smith' | ||
|
||
puts "HASH: #{person.serializable_hash}" | ||
puts "JSON: #{person.to_json}" | ||
puts "XML : #{person.to_xml}" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../../lib") | ||
|
||
require 'rubygems' | ||
require 'neo4j' | ||
require 'neo4j/extensions/activemodel' | ||
|
||
class Person | ||
include Neo4j::NodeMixin | ||
include ActiveModel::Validations | ||
|
||
property :first_name | ||
property :last_name | ||
|
||
validates_presence_of :first_name, :last_name | ||
end | ||
|
||
|
||
Neo4j::Transaction.run do | ||
person = Person.new | ||
|
||
puts person.valid? | ||
puts person.errors.inspect | ||
person.first_name = "Hej" | ||
person.last_name = "hop" | ||
puts person.valid? | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters