我的表单中有一个字段应该接受 ATOM 和 RSS 提要作为输入,我如何在我的模型中编写验证代码来验证是否只提供了提要作为输入。
最佳答案
你可以使用this来自进料检测器。 是的,它检测提要,但您可以使用正则表达式检查模型的 url 是否匹配
来自代码:
matches |= html.scan(/<link.*href=['"]*([^\s'"]+)['"]*.*application\/atom\+xml.*>/)
matches |= html.scan(/<link.*application\/atom\+xml.*href=['"]*([^\s'"]+)['"]*.*>/)
# matches |= atom_feed
matches |= html.scan(/<link.*href=['"]*([^\s'"]+)['"]*.*application\/rss\+xml.*>/)
matches |= html.scan(/<link.*application\/rss\+xml.*href=['"]*([^\s'"]+)['"]*.*>/)
# matches |= rss_feed
关于ruby-on-rails - 如何验证 ATOM 和 RSS 提要的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14397027/