Rails + Ransack - Drop Down List Collection?

后端 未结 2 1163
清酒与你
清酒与你 2021-02-04 03:13

I am loving the ransack gem for its flexibility, however I am unable to get the standard collection_select to function properly. Perhaps someone can assist.

Example:

相关标签:
2条回答
  • 2021-02-04 04:11

    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 %>
    
    0 讨论(0)
  • 2021-02-04 04:13

    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.

    0 讨论(0)
提交回复
热议问题