开发者

Help understand validates_each Rails helper

class User < ActiveRecord::Base 
     validates_each :name, :email do |model,开发者_JAVA技巧 attr, value|
             if value =~ /groucho|harpo|chico/i 
                   model.errors.add(attr, "You can't be serious, #{value}")
              end 
     end
end

Confused as to how this works.

Is :name, email the items it will loop?


:name and :email are the attributes that will be validates using this block.

So each time a User is validated, the block will be called once with attr = :name and once with attr = :email (and each time value will hold the value of that attribute).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜