我有一個collection_select場這裏列出:Rails 5.1如何不在collection_select中列出空值?
<%= form.collection_select :parent_id, Document.order(:name), :id, :name,
{:include_blank => ''}, {:class => 'form-control'} %>
名稱字段中有某些情況下空。我只想列出collection_select中的名稱,如果它不爲null。
有沒有辦法做到這一點?
謝謝。我需要調整它,因爲它是一個空字符串。這就是我最終完成的作品。範圍:named_documents, - > {where(「name <>''」).order(:name)} – spacerobot
您是否認爲應該通過在模型中添加NOT NULL常量和驗證來解決這個問題? – max
不,我正在使用acts_as_tree和jstree來構建文件管理器的樹。有時如果該字段不是類別標題,則該字段將是空的。 – spacerobot