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

前端 未结 8 1670
终归单人心
终归单人心 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 07:06

    <%= f.select :email_provider, ["gmail","yahoo","msn"]%>

    0 讨论(0)
  • 2020-12-02 07:09

    Rails drop down using has_many association for article and category:

    has_many :articles
    
    belongs_to :category
    
    <%= form.select :category_id,Category.all.pluck(:name,:id),{prompt:'select'},{class: "form-control"}%>
    
    0 讨论(0)
提交回复
热议问题