Rails + Ransack - Drop Down List Collection?

走远了吗. 提交于 2019-12-02 22:43:29

Seems that this will work.

<%= f.select :project_id_eq, options_from_collection_for_select(Project.all, "id", "name", @search.project_id_eq) %>

If anyone has another suggestion, would love to know it too.

To do this with an include_blank, put it outside of the parentheses:

ex:

<%= f.select :languages_id_eq, options_from_collection_for_select(Language.all, "id", "name"), include_blank: true %>

== UPDATE ==

better yet, use f.collection_select. This way after the user searches for something using the drop down, that option is preselected on the following page:

<%= form.collection_select :vendor_id_eq, Vendor.all, :id, :name, include_blank: true %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!