2016-09-29 56 views
0

在我正在構建的學習RoR的應用程序中,我使用標記(非常像帖子和註釋)具有Annotation(用於文檔類型的文檔)。在向註釋添加標籤時,我想將標籤的可能類型限制爲與註釋的文檔類型具有相同文檔類型的標籤類型。Rails 5 - 限制關聯對象的選擇

爲了減少標籤類型的列表,我已經使用範圍來獲得活動標籤類型。像這樣:

<%= f.association :documenttype, :collection => Documenttype.active.order(:name) %> 

這個範圍

scope :active, -> { where(active: true) } 

如何延長它匹配的文件類型?如果用範圍,如何;如果不是,我應該採取什麼方法?

回答

0

找到了解決辦法:增加對:collection像這樣多個過濾器...

<%= f.association :tagtype, prompt: 'Select tag type', label: false, :collection => Tagtype.active.order(:name).where(:documenttype => @annotation.documenttype_id) %>