5
<%= f.check_box :openid_enabled %>
<%= f.label :openid_enabled, 'OpenID' %>

Above code generate this HTML

<input type="hidden" value="0" name="application[openid_enabled]">
<input type="checkbox" value="1" name="application[openid_enabled]" id="application_openid_enabled">
<label for="application_openid_enabled">OpenID</label>

and the label is getting displayed like

[x]
OpenID

instead of

[x] OpenID

Do I need to style it or rails helpers have some build in functionality?

Added

I am using twitter bootstrap CSS framework in my Rails application.

Amit Patel
  • 15,609
  • 18
  • 68
  • 106

3 Answers3

5

This must be happening because either input or label is set as display: block; You can show it in one line by making these elements inline -

input, label{ display: inline; }
Dipak
  • 11,930
  • 1
  • 30
  • 31
5

I used following to fix the issue without overriding style of twitter bootstrap css.

<%= f.label :openid_enabled, class: 'checkbox' do %>
  <%= f.check_box :openid_enabled %>
  OpenID
<% end %>

Which generates following HTML

<label for="application_openid_enabled" class="checkbox">
  <input type="hidden" value="0" name="application[openid_enabled]">
  <input type="checkbox" value="1" name="application[openid_enabled]" id="application_openid_enabled">
  OpenID
</label>

Here is reference http://twitter.github.com/bootstrap/base-css.html

Thanks @MyHeadHurts and @Dipaks for your invaluable inputs.

Amit Patel
  • 15,609
  • 18
  • 68
  • 106
1

I know its old but the best way to do it today would be to use the checkbox-inline class on the label.

gbjbaanb
  • 51,617
  • 12
  • 104
  • 148