我想驗證我的應用程序中文本區域的字數。 我試過以下this SO question,但我不能讓我的工作。Rails 5客戶端驗證字數不起作用
我的驗證:
validates :skills_response, :length => {
:minimum => 5,
:maximum => 10,
:tokenizer => lambda { |str| str.scan(/\s+|$/) },
:too_short => "must have at least %{count} words",
:too_long => "must have at most %{count} words"
}
我現在用的是client side validations gem,正如你所看到的,上面是不工作的,因爲它仍然是字符計數。
我也曾嘗試:tokenizer => lambda { |str| str.split }
這也不能工作。爲什麼這會發生?