使用Rails将单选按钮标签放在与单选按钮相同的行上

时间:2014-07-01 11:35:49

标签: ruby-on-rails ruby-on-rails-4

Rails 4.1 引导 Bootstrap_forms

我想看到与单选按钮位于同一行的标签。我试过这个:

<%= f.form_group do %>
  <%= f.radio_button :role, 'member', :checked => true %>
  <%= f.label :role, 'Non-Candidate / Non-Staff', :style => "display:inline" %>
  <%= f.radio_button :role, 'candidate' %>
  <%= f.label :role, 'Candidate', :style => "display:inline" %>
  <%= f.radio_button :role, 'campaign_staff' %>
  <%= f.label :role, 'Campaign Staff', :style => "display:inline"  %>
<% end %>

但它没有用。标签位于下一行。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您可以使用表格,只需将label代码<%= f.label :role, 'Non-Candidate / Non-Staff', :style => "display:inline" %>放在radio_button代码旁边,即<%= f.radio_button :role, 'member', :checked => true %>,然后将它们放在<td></td> tags之间} .Same适用于剩余的。

<%= f.form_group do %>
  <table>
  <tr>
  <td><%= f.radio_button :role, 'member', :checked => true %><%= f.label :role, 'Non-Candidate / Non-Staff', :style => "display:inline" %></td>

  <td><%= f.radio_button :role, 'candidate' %><%= f.label :role, 'Candidate', :style => "display:inline" %></td>

  <td><%= f.radio_button :role, 'campaign_staff' %><%= f.label :role, 'Campaign Staff', :style => "display:inline"  %></td>
  </tr>
 </table>
<% end %>

以下是我们的工作代码段

<tr>
<td><%= "Employee Type" %></td>
<td><%= radio_button 'employee', 'employee_type', "employee" %><%= "Employee" %></td>
<td><%= radio_button 'employee', 'employee_type', "retainer" %><%= "Retainer" %></td>
<td><%= radio_button 'employee', 'employee_type', "doctor" %><%= "Doctor" %></td>
</tr>

这是截图

enter image description here