I m in a situation where i need to convert an Object to string so that i can check for Invalid characters/HTML in any filed of that object.
Here is my function for spam check
def seems_spam?(str)
flag = str.match(/<.*>/m) || str.match(/http/) || str.match(/href=/)
Rails.logger.info "** was spam #{flag}"
flag
end
This method use a string and look for wrong data but i don’t know how to convert an object to string and pass to this method. I tried this
@request = Request
spam = seems_spam?(@request.to_s)
Please guide
Thanks
You could try
@request.inspectThat will show fields that are publicly accessible
Edit: So are you trying to validate each field on the object?
If so, you could get a hash of field and value pairs and pass each one to your method.
If you’re asking about implementing a to_s method, Eugene has answered it.