2011-11-17 91 views
3

我已經建立了一個多選的形式(從內部的form_for)是這樣的:顯示先前選擇的選擇

<div class="rounded-block quarter-wide radio-group"> 
    <h4>Exclude customers from source:</h4> 
    <%= f.select :excluded_sources, options_for_select(User.select(:source).group(:source).order(:source).map {|u| [u.source,u.source]}), {:include_blank => false}, {:multiple => true} %> 
    <%= f.error_message_on :excluded_sources %> 
</div> 

這很適合我的需要。唯一的問題是,當我回到顯示選項的頁面時,我看不到之前選擇的內容(即在渲染時已經在數據庫中的內容)。有沒有簡單的方法讓軌道顯示之前選擇的內容?我寧願不切換到複選框。

在我的匹配曲線模型

(對應於存儲excluded_sources表),我有這個:

serialize :excluded_sources 
+0

如何在db中存儲'excluded_sources'?序列化的列,逗號分隔值或在另一個表中? – rubyprince

+0

連載列。我會更新我的問題 – Ramy

回答

3

這結束了有關片:

:selected => matching_profile.send(:excluded_sources) 

這裏:

<div class="rounded-block quarter-wide radio-group"> 
<h4>Exclude customers from source:</h4> 
<%= f.select :excluded_sources, options_for_select(User.select(:source).group(:source).order(:source).map {|u| [u.source,u.source]}, :selected => matching_profile.send(:excluded_sources)), {:include_blank => false}, {:multiple => true} %> 
<%= f.error_message_on :excluded_sources %> 

+0

這是什麼是matching_profile? –