如何在Rails表单的同一行保留复选框和标签?
我应该怎么做才能将复选框的标签与包含表单的rails视图中的复选框保持在同一行上?
目前该标签出现在下一行:
<div class="span6 offset3">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :name %>
<%= f.text_field :name %>
<br>
<%= f.check_box :terms_of_service %>
<%= f.label :terms_of_service, "I agree to the #{link_to 'Terms of Service', policies_path}.".html_safe %>
<br><br>
<%= f.submit "Create my account", :class => "btn btn-large btn-primary" %>
<% end %>
谢谢你,亚历山德拉
看起来您使用的是Bootstrap,因此我建议您调整视图代码以使用本节Bootstrap文档中描述的水平表单布局:http://getbootstrap.com/css/#forms
根据引导维基,它必须是
<label class="checkbox">
<input type="checkbox"> Check me out
</label>
这在Ruby on Rails中是
<%= f.label :terms_of_service do %>
<%= f.check_box :terms_of_service %>
I agree to the <%= link_to 'Terms of Service', policies_path %>.
<% end %>
<br>
<%= f.check_box :terms_of_service, :style => "float:left;" %>
<%= f.label :terms_of_service, "I agree to the #{link_to 'Terms of Service', policies_path}.".html_safe, :style => "float:left;" %>
<br>
链接地址: http://www.djcxy.com/p/41451.html
上一篇: How to keep a checkbox and label on the same line in a Rails form?