Last active
December 9, 2021 05:16
-
-
Save billyyarosh/65bfe0d8c6dc576a1d297c8d4e2b2348 to your computer and use it in GitHub Desktop.
Song class
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
class Song | |
include ActiveModel::Model | |
include ActiveModel::Attributes | |
include ActiveModel::Serializers::JSON | |
attr_accessor :name, :artist, :genre, :id | |
validates_presence_of :name, :artist | |
def attributes=(hash) | |
hash.each do |key, value| | |
send("#{key}=", value) | |
end | |
end | |
def attributes | |
{ | |
'name' => nil, | |
'artist' => nil, | |
'genre' => nil, | |
'id' => nil, | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment