[Ruby] ruby on rails, formatting check_box

Dave Myron dave.myron at contentfree.com
Wed Aug 1 13:43:58 PDT 2007


> <input id="content_segment_needs_review"
> name="content_segment[needs_review]" type="checkbox" value="1">Needs
> Review</input>

Is this even valid HTML? I don't think so.

Usually, it's best to wrap your input with the label, so:
<label for='content_segment_needs_review'><input
id='content_segment_needs_review' name='content_segment[needs_review]'
type='checkbox' value='1' /> Needs review</label>

Similar to what you have, but valid. 

To get line breaks to handle the way you want you, might try using some CSS,
specifically: label{ white-space: nowrap }. Might work. Haven't tried it.

Also, about the hidden field: that's to guarantee Rails gets either a yes or
no value for the field. If the hidden field isn't there and the checkbox is
left unchecked, Rails doesn't get the value (I believe... or if it does,
it's just nil which is not usually what is wanted for a boolean checkbox).

Hope that helps,
Dave 



More information about the Ruby mailing list