简体   繁体   English

Rails验证发布请求

[英]Rails validating post request

Is there a gem or easy way to validate a API post request? 有没有一种简单的方法可以验证API发布请求? For example I am always expecting a field to be either present or always a string and if it is not to ignore the request all together. 例如,我一直期望一个字段要么存在要么总是一个字符串,如果不一起忽略请求的话。

Or is the only way to do this is to manually check each request coming in with an IF statement? 还是唯一的方法是手动检查每个带有IF语句的请求?

一旦获得请求,请检查控制器中的参数,以及是否需要使用参数以允许发布->如果不向发布请求返回nil,则创建/更新数据库记录。

I think you should assign a Model to your "request". 我认为您应该为您的“请求”分配一个模型。 This way you could "validate" presence of any given fields 这样,您可以“验证”任何给定字段的存在

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM