すべて、一部、または 1 つのクラスを選択する部分的なチェックボックス フォームがあります。
<p>
<%= check_box_tag(:all) %>
<%= label_tag(:all, "All subjects") %>
</p>
<p>
<% @subjects.each do |subject| %>
<%= check_box_tag(subject.id) %>
<%= label_tag(subject.id, subject.name) %>
<br />
<% end %>
</p>
次の HTML を生成します。
<p>
<input id="all" name="all" type="checkbox" value="1" />
<label for="all">All subjects</label>
</p>
<p>
<input id="1" name="1" type="checkbox" value="1" />
<label for="1">English</label>
<br />
<input id="2" name="2" type="checkbox" value="1" />
<label for="2">Basket_Weaving</label>
<br />
<input id="3" name="3" type="checkbox" value="1" />
<label for="3">Math</label>
<br />
</p>
rspecを使用して、各サブジェクトがビューに表示されていることをテストしたい-
it "should have a box for each subject" do
@eval_selektor
@student_group.subjects.each do |subject|
response.should ??????
end
end
私はresponse.should have_selector('id' content: subject.id) but that throws
未定義の方法を試しましたinclude?' for 1:Fixnum
(実際にはあまり意味がありません)、ここで示すようにxpath/cssも試しました。