Created
October 3, 2018 03:40
-
-
Save clarkngo/f541545896e9d83d478ce312cd24ed84 to your computer and use it in GitHub Desktop.
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 Book < ApplicationRecord | |
validates :title, presence: true | |
validates :author, presence: true | |
validates :genre, presence: true | |
validates :classification, presence: true, :inclusion { :in => @allowed_classifications } | |
@allowed_classifications = [ | |
'General Works - encyclopedias', | |
'Philosophy, Psychology, Religion', | |
'History - Auxiliary Sciences', | |
'History (except American)', | |
'General U.S. History', | |
'Local U.S. History', | |
'Geography, Anthropology, Recreation', | |
'Social Sciences U', | |
'Political Science V', | |
'Law Z - Bibliography and Library Science', | |
'Education', | |
'Music', | |
'Fine Arts', | |
'Language and Literature', | |
'Science', | |
'Medicine', | |
'Agriculture', | |
'Technology', | |
'Military', | |
'Naval Science', | |
'Bibliography and Library Science', | |
'type' | |
] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recommend using a class method called
classifications
instead of an instance variable here which returns an array. Also, you're missing thebook_type
andyear
validations.