codesw1tch
codesw1tch

Reputation: 720

Is it possible to do some Javascript in a Rails Model validation method?

I basically want to only allow users to register if they have entered or have been geolocated at a valid location. I thought the way to validate location would be to use google's geolocation API, to convert the string address the user enters into latitude and longitutide. I would love to do this in a custom validation method in my User model, but I need to use Javascript to access Google's API.

Is there a good way to do this? Is there a better way to solve this problem? Thanks!

Upvotes: 0

Views: 50

Answers (1)

Enoban
Enoban

Reputation: 26

If you are using Google API's Geolocation, you can valudate data using Javascript and then send that data to your controller via Ajax (jQuery can do that). This way, after the validation success, your controller can register the new user. Your controller can interact directly with the model.

Upvotes: 1

Related Questions