Hi guys i am trying to validate a field in a form. I dont want that field to contain a certain string. Lets say if a user types : "i want to kill you" he gets a message : Change the message! How can i do that?
you can to that using a js, putting into application.js, calling the function on the change focus
Leoncio Caminha wrote in post #1010607:
you can to that using a js, putting into application.js, calling the function on the change focus
how can i call the function on the change focus? on(change)....?
can i do that inside the controller without a js?
maybe with :onchange works fine, well…about that validation inside controller…is not a best practice, the better way is into model, using a method validates_each, this method will validate any condition with the respective field, any doubt, please just talk
i hope it help dude
Thank you Leoncio. I am going to do the validates_each inside the model. But how can i pass the string as a parameter? basically this what i want to do
validates_each :field.value, if field.value.eql?(bla bla bla) :message => "Please write smth that makes sense."
How can i do that?
solved with a new method and a validate :method
cool this work too
good luck!