【发布时间】:2014-11-06 01:40:34
【问题描述】:
这两种实现在功能上是否相同?如果是这样,哪个“更好”?
# from a model
WIDGET_COLORS = %w(red yellow green)
validates :widget_color,
inclusion: {in: WIDGET_COLORS, allow_nil: true}
或
# from a model
WIDGET_COLORS = %w(red yellow green)
validates :widget_color,
inclusion: {in: WIDGET_COLORS},
allow_nil: true
更新:修正错字,因此示例读取 validates
【问题讨论】:
标签: ruby-on-rails validation inclusion