もともと私は次のようなビュー設定をしていました:
<%= render layout: 'form' do |f| %>
<% for holiday in Holiday.find(:all) %>
<label class="checkbox">
<%= check_box_tag "user[holiday_ids][]", holiday.id, @user.holidays.include?(holiday) %>
<%= holiday.name %>
</label>
8つの「興味」のリストをレンダリングしました。ただし、チェック時にそれらの下にdivを表示するjqueryの表示/非表示機能を使用するには、これら8つのうち3つに一意のdiv idを付ける必要がありました。これを行うには、上記の erb コードによってレンダリングされた html を取り、それをビューに貼り付け、手動で変更して jquery ステートメントで動作するようにしました (以下に貼り付けます)。私の質問は、jquery i によって表示されるこれらの div でアプリ内の別のモデルによって入力されるドロップダウンが必要です..どうすればこれを達成できますか? 最初の div でステートメントを実行しようとしましたが、次のエラーが発生しました (_form パーシャルから取得したコード):
undefined method `map' for nil:NilClass
Extracted source (around line #12):
9: </ul>
10: </div>
11: <% end %>
12: <%= yield f %>
13:
14: <div class="actions">
15: <%= f.submit "Continue" %>
ここに私の _form 部分があります:
<%= form_for @user, url: wizard_path do |f| %>
<% if @user.errors.any? %>
<div class="error_messages">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= yield f %>
<div class="actions">
<%= f.submit "Continue" %>
or <%= link_to "skip this step", next_wizard_path %>
</div>
<% end %>
ここに私が試みているHTML + erbステートメントがあります..
<%= render layout: 'form' do |f| %>
<div id="checkbox">
<label class="checkbox">
<input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="2" />
Valentine Day
</label>
</div>
<div style="display:none;">
<%= select_tag 'Interests', options_for_select(@interests) %>
</div>
<div id="checkbox">
<label class="checkbox">
<input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="4" />
Mothers Day
</label>
</div>
<div style="display:none;">
Whatever you have to capture here<input type="text" id="foo2" />
</div>
<label class="checkbox">
<input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="7" />
Thanksgiving
</label>
<div id="checkbox">
<label class="checkbox">
<input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="5" />
Father's Day
</label></div>
<div style="display:none;">
Whatever you have to capture here<input type="text" id="foo3" />
</div>
<label class="checkbox">
<input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="3" />
Easter
</label>
<label class="checkbox">
<input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="6" />
Halloween
</label>
<label class="checkbox">
<input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="8" />
Christmas
</label>
<% end %>