Last active
December 23, 2022 02:32
-
-
Save brunopgalvao/6d86e8e2c570f86823ea to your computer and use it in GitHub Desktop.
HTML5 Datalist using Ruby on Rails form_for
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for @person do |f| %> | |
<%= f.label :first_name, "First Name" %>: | |
<%= f.text_field :first_name, list: 'first-name' %> | |
<datalist id="first-name"> | |
<% Person.all.each do |person| %> | |
<option value="<%= person.first_name %>"></option> | |
<% end %> | |
</datalist> | |
<%= f.submit %> | |
<% end %> | |
You may also want to do distinct: | |
<% Person.select(:first_name).distinct.each do |person| %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this @brunopgalvao!!