Rails Populating SELECT Parameters from a Database

I feel that it is simple, but I cannot find the details anywhere.

I have a basic application created by creating a scaffold.

A form that enters data is already built into this form. I have a SELECT (dropdown) field in a form. I would like to be able to get OPTIONS in this selection box from the database. Ideally, the end user will be able to add and edit these parameters.

I have no idea how to associate this SELECT field in my form with where OPTIONS will be MEMORED.

Can someone point me in the right direction, as far as terminology, as a study? I come up. I feel that this should be commonplace.

+8
ruby-on-rails html-select
source share
1 answer

As a ByScripts reference, a script works here (for those where time is not a luxury):

<%= collection_select(:lang_id, 0, Language.all, :id, :name) %> 

Where Language is a table with one column with the name "name" and an automatically assigned column identifier; :lang_id is the name of the element, and 0 is the default index when loading the page.

+19
source share

All Articles