Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'data_mapper'
- DataMapper.setup(:default, "sqlite::memory:")
- class Post
- include DataMapper::Resource
- property :id, Serial
- property :title, String
- after :create do
- self.title = "The id is #{id}"
- save
- end
- end
- DataMapper.finalize
- DataMapper.auto_migrate!
- post = Post.new
- if post.save
- puts 'Successfully saved.'
- else
- puts "Errors: #{post.errors.size}"
- end
- p DataMapper::VERSION, post, post.title
- # called with 'ruby -rubygems saveaftercreate.rb' outputs:
- # Errors: 0
- # "1.1.0"
- # #<Post @id=1 @title="The id is 1">
- # "The id is 1"
Add Comment
Please, Sign In to add comment