Ruby on Rails Sunday, April 2, 2017

You seem to be comparing apples and oranges here. val() is from jQuery and trim() is from JavaScript. #blank? is from Rails (not Ruby). Which one or combination you might use are entirely up to you, and depend on your use-case.

If you want to provide a convenience to your users, and are helping them avoid entering missing or malformed data (but critically, are not relying on this protection to be complete or even present, since JavaScript can be turned off in a browser), then by all means use trim and val and have fun.

If you are going to rely on the data being present before you create a new record in your database, then you had best be using Ruby (and the language extensions Rails provides to it) to do that.

The professional solution would be to use both, so that you can be helpful AND safe.

Walter

> On Apr 1, 2017, at 4:19 PM, fugee ohu <fugee279@gmail.com> wrote:
>
> is this a better way to check for empty form field inputs than trim and val combined?
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/77bb0568-31f0-4804-a4ff-7734527d063e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/EE461E97-5006-40FF-9B1E-8A356025B4CE%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment