How to have a drop down <select> field in a rails form?

前端 未结 8 1725
终归单人心
终归单人心 2020-12-02 06:23

I am creating a scaffold -

rails g scaffold Contact email:string email_provider:string 

but I want the email provider to be a drop down (wi

8条回答
  •  囚心锁ツ
    2020-12-02 06:52

    You can take a look at the Rails documentation . Anyways , in your form :

      <%= f.collection_select :provider_id, Provider.order(:name),:id,:name, include_blank: true %>
    

    As you can guess , you should predefine email-providers in another model -Provider , to have where to select them from .

提交回复
热议问题