In my application, users pick train stations from an autocompleting text field. Since there aren't many train stations (~100), I'd prefer for the field to autocomplete based on the contents of a client-side array rather than querying the server each time the user types a character (the goal is to make the autocomplete more responsive).
My question is how to do this in Rails in a maintainable, non-hacky way. My current solution is just putting this line at the bottom of index.html.erb
:
<%= javascript_tag "var stations = #{Station.all.map {|s| s.name}.to_json}" %>
but this isn't great (for one thing, I have to remember the "stations" variable name while I'm working on application.js
).