ruby-on-railsfilteringruby-on-rails-5countrycity

Ruby on Rails5: Filtering users by City / Country


what is the best way to structure Location information for users? I need to be able filter hundreds of users by City/Country.

Currently I have created a free-text string for location as I could not find any gem for whole cities grouped under countries. Btw this is a custom scaffold, not devise.

enter image description here

Should I just enter as free-text as in city, country and then filter based on that string with alike?

Thank you


Solution

  • I don't recommend usage of free-tex input because you will get different possible entries for the same city and country which will make filteration an impossible task. It is always better to use a drop down list.

    Here is a full list of countries and cities using java script.

    change the location attribute with two attributes country and state and use the previous list to fill them.