Skip to content

Instantly share code, notes, and snippets.

@alexshagov
Created May 9, 2016 12:30
Show Gist options
  • Save alexshagov/28df2c0a2c7dd88b46a2edd4f342bf76 to your computer and use it in GitHub Desktop.
Save alexshagov/28df2c0a2c7dd88b46a2edd4f342bf76 to your computer and use it in GitHub Desktop.
blog 2-4
class PostForm
include Virtus
include ActiveModel::Model
#Post attributes
attribute :title, String
attribute :body, String
#Tag attributes
attribute :tags, Array[Integer], default: []
#Validations
validates :title, :body, presence: true
def save
if valid?
persist!
else
false
end
end
def update
if valid?
update!
else
false
end
end
private
def persist!
end
def update!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment