i have resolved with this:
#prevent users to write text uppercase, and reset field text to
lowercase
validates_each :title, :description do |model, attr, value|
size_letters = value.scan(/\w/).size
size_invalid = value.scan(/[A-Z]/).size
if size_invalid > 0
if (size_letters / size_invalid) < 4 and size_letters > 10
model.errors.add( attr,
I18n.t('activerecord.errors.messages.uppercase'))
model.write_attribute(attr, value.downcase)
end
end
end
for Hassan Schroeder: i want the user write in uppercae only certain
letters( itials of names, letter after points, etc..). with my solution
i concur the user to write in the text the 25% of letters uppercase.
thanks to all.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.