2012-12-03 15 views
1

我使用acts-as-taggable-on來保存多個用戶的興趣。我試圖在註冊表單上顯示一個固定的複選框列表。下面的代碼工作。設計form_for,如何使用數組check_box_tag

= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| 
%p 
    - ["music","art","movies"].each do |interest| 
    = check_box_tag "user[interested_list][]", interest 

問題是,當敲「提交」,如果頁面重載,因爲有些領域缺少我沒有看到前面的複選框選中,他們都復位。

我明白我失去了價值,但使用這樣的事情我一直在努力,但它不工作

= check_box_tag "user[interested_list][]", interest, params[:user][:interested_list][interest] 

我收到以下錯誤

未定義的方法`[]」爲無:NilClass

任何想法?

回答

0

已解決。

我只需要檢查值是否存在於數組中。

= check_box_tag "user[interested_list][]", interest, session[:interested_list].include?(interest)