<%= collection_select(:catgory, :id, @categories, :id, :title, {}, data: { behavior: 'category_dropdown' }) %>
在上面的代碼中,我需要將參數傳遞給title方法。有沒有辦法用collection_select來做到這一點?將參數傳遞給text_method的集合選擇方法
<%= collection_select(:catgory, :id, @categories, :id, (:title, @program), {}, data: { behavior: 'category_dropdown' }) %>
編輯: 縱觀內部的collection_select的text_method。它最終傳遞給.send方法,該方法應該允許element.send(:title,@program)。但是,我認爲爲什麼仍然無法傳遞參數的問題是,collection select正在讀取(:title,@program)作爲兩個參數而不是一個參數。
你有訪問在您的類別模型中使用@program? – InternetSeriousBusiness 2012-08-02 16:41:19
不幸的是它是一個has_many關係,所以我需要通過程序來知道哪個程序要放在標題中。 – John 2012-08-02 16:42:45