How to keep a checkbox and label on the same line in a Rails form? How to keep a checkbox and label on the same line in a Rails form? ruby-on-rails ruby-on-rails

How to keep a checkbox and label on the same line in a Rails form?


According to the bootstrap wiki, it must be

<label class="checkbox">  <input type="checkbox"> Check me out</label>

which in Ruby on Rails is

<%= f.label :terms_of_service do %>  <%= f.check_box :terms_of_service %>  I agree to the <%= link_to 'Terms of Service', policies_path %>.<% end %>


It looks like you're using Bootstrap, so I recommend adapting your view code to use the horizontal form layout described in this section of the Bootstrap docs: https://getbootstrap.com/docs/4.3/components/forms/#horizontal-form


 <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>