Class | Scrivener |
In: |
lib/scrivener/validations.rb
lib/scrivener.rb |
Parent: | Object |
VERSION | = | "1.1.0" |
Initialize with a hash of attributes and values. Extra attributes are discarded.
@example
class EditPost < Scrivener attr_accessor :title attr_accessor :body def validate assert_present :title assert_present :body end end edit = EditPost.new(title: "Software Tools") edit.valid? #=> false edit.errors[:title] #=> [] edit.errors[:body] #=> [:not_present] edit.body = "Recommended reading..." edit.valid? #=> true # Now it's safe to initialize the model. post = Post.new(edit.attributes) post.save