Skip to content

Instantly share code, notes, and snippets.

@AshikNesin
Last active September 16, 2015 09:33
Show Gist options
  • Save AshikNesin/7cc53bccbf77552d9430 to your computer and use it in GitHub Desktop.
Save AshikNesin/7cc53bccbf77552d9430 to your computer and use it in GitHub Desktop.
[Rails] Retrieve from database and populate it to combo box

Basically we are going to retrieve the details from database (in my case its employee name & their number) and assign it to an array.

Then we populate that array to the select

# /app/views/payslips/index.html.erb
<% emp_array = Employee.all.map { |emp| [emp.name, emp.emp_no] } %>
<%= f.select :emp_no, options_for_select(emp_array) %> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment