0
我使用的是Activeadmin,並有一個表單,用戶可以選擇他們想要添加note
的notebook
。基於事先選擇的Rails集合
f.input :notebook
f.input :note, as: :select, collection: Note.all
但是,我希望能夠根據用戶選擇的筆記本動態更改該集合。如果筆記本的notebook_type
爲evernote
,我不想讓用戶選擇Note.all
中包含的某些筆記。 (我已經在一個非常親切的StackOverflow用戶的幫助下得到了這個範圍)。
僅供參考,下面的方法:
class Notebook < ActiveRecord::Base
has_many :notes
def self.notes_without_check_lists
all.reject { |notebook| notebook.notes.any? { |note| note.note_type == 'check_list' } }
end
end
我已經在使用一些jQuery來處理表單的另一部分,並使用上改變事件是這樣的:
$("#note_notebook_id").on 'change', (e) ->
但從本質,我想以某種方式在Note.all
和Note.notes_without_check_lists
之間切換collection:
,具體取決於用戶選擇了哪個Notebook。
非常感謝您的任何幫助。