validate 和 validates 的区别,都是 rails 的验证器么?
Where did you see validate? I have not seen it before...
validate
validate 后面接个函数名用成员函数验证,validates 接 hash,是 validates_xxx 的统一入口
validates
validates_xxx
#1 楼 @blacktulip validate :client, :error => :invalid_client validate :redirect_uri, :error => :invalid_redirect_uri validate :attributes, :error => :invalid_request validate :response_type, :error => :unsupported_response_type validate :scope, :error => :invalid_scope
def initialize(client, resource_owner, attributes) ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", attributes[attr]) } @resource_owner = resource_owner @client = client validate end
#2 楼 @doitian 没有明白。 以 validate :redirect_uri, :error => :invalid_redirect_uri 为例,它的意思是?
#4 楼 @zhangyuxiu validates 是用这些 helpers, presence 这些现成的 验证器 。当现有的 验证器 满足不了你,你就需要使用自定义方法 即 validate 来验证。你的写法我还真没见过,估计是很古老的 API 吧。如果你需要验证 redirect_uri 必须赋值,应该用
redirect_uri
validates :redirect_uri, :presence => true