Created
May 9, 2016 12:30
-
-
Save alexshagov/28df2c0a2c7dd88b46a2edd4f342bf76 to your computer and use it in GitHub Desktop.
blog 2-4
This file contains hidden or 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
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