[Ruby] ruby on rails, formatting check_box

Frank Schwieterman fschwiet at gmail.com
Wed Aug 1 12:56:18 PDT 2007


  Hi I'm new to Ruby on Rails, working on my first project for educational
purposes.  The coding is fun but I'm getting hung up on page layout.  :(
This is a rails specific question but I thought I'd try the Seattle alias.
werd to 206

  I have some questions about the check_box forms helper.  Documentation is
here:
http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html#M000501

  I'm trying to fit a bunch of form controls into a wide + narrow area.  I
don't want the checkbox to be on line and the label to be on another due to
linesplitting.  As my checkbox is now, it can be split.  I have in
_form.rhtml:

<label for="content_segment_needs_review">Needs review</label>
<%= check_box 'content_segment', 'needs_review', {}, "1", "0"  %>

which produces HTML:

<label for="content_segment_needs_review">Needs review</label>
<input id="content_segment_needs_review"
name="content_segment[needs_review]" type="checkbox" value="1" /><input
name="content_segment[needs_review]" type="hidden" value="0" />

The text in <label> can be split on a different line from <input>.  I would
prefer the below to be generated, as the label cannot be split from the
checkbox.  Anyone have any ideas?


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


The documentation for check_box indicates their is an options parameter but
does not document what options are allowed.  Perhaps it can be used.  I'm
also curious what the second hidden input is for.


More information about the Ruby mailing list