我在视图页面中显示复选框,数据将来自数据库。这是我的代码,问题是循环时如果出现相同的父名称,它会显示相同的父复选框两次。
<% @permission.each do |f| %>
<% if @controller_code != f.controller_code %>
<% @controller_code = f.controller_code %>
<%= check_box_tag "cntrl_#{f.controller_code}", f.controller_code, false, :class => "Par_#{f.controller_code}", :id => "Par_#{f.controller_code}" %> <%= f.controller_name %>
<br/>
<% @permission.each do |f| %>
<% if @controller_code == f.controller_code %>
<%= check_box_tag "action_#{f.controller_code}_#{f.action_code}",f.action_code, false, :class => "Child_#{f.controller_code}", :id => "Child_#{f.controller_code}_#{f.action_code}" %> <%= f.action_name %>
<br/>
<% end %>
<% end %>
<% end %>
我也尝试过这种方式,但它不能正常工作..
<% @permission.each do |f| %>
<% if @controller_code != f.controller_code %>
<% @controller_code = f.controller_code %>
<%= check_box_tag "cntrl_#{f.controller_code}", f.controller_code, false, :class => "Par_#{f.controller_code}", :id => "Par_#{f.controller_code}" %> <%= f.controller_name %>
<br/>
<% end %>
<%= check_box_tag "action_#{f.controller_code}_#{f.action_code}",f.action_code, false, :class => "Child_#{f.controller_code}", :id => "Child_#{f.controller_code}_#{f.action_code}" %> <%= f.action_name %>
<br/>
<% end %>