I’m new to RoR/Gems, this is a basic question.
I created a gem, MyNameGem, in order to learn the process. It contains these methods:
def returnValidationString1
puts 'Validation String'
end
def returnValidationString2
puts 'ANother Validation String'
end
I included the gem in a simple rails app, everything seems to be working as expected.
I this to my model:
validates :name => MyNameGem.returnValidationString1
What I’m trying to create is a gem that I can use inside a validation routine. So, for example, I want to do this: validates :name => (call my gem method, return a string, and use that string as the validation requirement)
The function of
putsis to put things to the console, so that’s exactly what it will do. What your validates call is doing is kind of unusual though, and doesn’t seem to make any sense. Your code evaluates to:That really doesn’t mean anything.
putsusually returnsnil.If you want to write a custom validation routine that’s stored in a gem, that’s a different question.