Rails - 表格列的宽度受选择框的影响

问题描述:

我有一个表似乎适应给定列中最长的文本字符串。我在每行中都有选择标签,这些标签看起来很乱。有一个额外的列被添加到表中,右边的边框不显示。如果我缩小了选择标记的大小,表格格式正确,但我想让表格符合下一列中最大选择标记和最大按钮的大小。谢谢。下面的代码:Rails - 表格列的宽度受选择框的影响

<table class="table table-bordered table-condensed"> 
<thead> 
<tr> 
    <th>Position</th> 
    <th>Allocation</th> 
    <th>Action</th> 
</tr> 
</thead> 

<% position_map = @cabinet.cabinet_position_map %> 
<% @cabinet.cabinet_type.usize.downto(1) do |i| %> 
<tr> 
    <td>Slot: <%= i %></td> 
    <% if position_map[i].nil? %> 
     <% cabinet_device_selection = @cabinet.devices_to_fit(position_map, i) %> 
     <% @selection_list = [ "Power", "I/O", "Interface", "Unusable", "Other", "Missing", "Reserve" ] %> 
     <% cabinet_device_selection.each do |device| %> 
      <% @selection_list << device.name %> 
     <% end %> 
     <% if position_map[i].nil? %> 
       <%= form_tag({:controller => :cabinets, :action => :update_device_position, :position => i , :id => @cabinet.id } , { :method => 'get', :class => "form-search" }) do %> 
        <td> 
         <%= select_tag :position_name, options_for_select(@selection_list) %> 
        </td> 
        <td> 
         <%= hidden_field_tag 'position', i %> 
         <%= submit_tag "Add" , :class => "btn" %> 
        </td> 
       <% end %> 
     <% end %>    
    <% else %> 
     <% position_map[i].each do |cabinet_item| %> 
      <td> 
       <%= cabinet_item.name %>&nbsp; 
      </td> 
      <td> 
       <%= link_to "Remove", { :controller => :cabinets, :action => :remove_cabinet_position, :id => @cabinet.id, :position => i}, :class => "btn btn-danger" %> 
      </td> 
     <% end %> 
    <% end %> 
</tr> 
<% end %> 
</table> 

而这里的输出是什么样子:

Ill formatted image

+0

?是否有可能将该红宝石代码转换为HTML并发布?我的意思是,你可以通过Chrome开发人员工具 – Learner 2013-03-08 17:28:19

看来你正在使用引导。

所以,要改变select_tag的宽度,你可以简单地做。或者,如果您想设置自定义宽度,请在您的css中添加一个类。

.option-small { 
     width: 100px !important; 
    } 

然后使用任何CSS u使用

<%= select_tag :position_name, options_for_select(@selection_list), :class => "option-small" %> 
+0

获得这个Ruby代码的html代码。嘿乔...有帮助吗?如果是,你会介意接受答案吗? :) – Bot 2013-03-13 09:05:05