Skip to content

Instantly share code, notes, and snippets.

@bryansray
Created August 16, 2008 22:48
Show Gist options
  • Save bryansray/5762 to your computer and use it in GitHub Desktop.
Save bryansray/5762 to your computer and use it in GitHub Desktop.
checkbox_control :is_searchable, :label => "Allow other #{SITE_NAME} members to search for me and view me on the members page?"
# Generates this:
<input type="checkbox" id="user_is_searchable" value="1" name="user[is_searchable]" class="checkbox" checked="checked"/>
<input type="hidden" value="0" name="user[is_searchable]" class="hidden"/>
<label for="user_is_searchable">Send me weekly motivator reports?</label>
# When this is submitted to the controller I get:
{ "user" => { "is_searchable" => "0" } }
# Even if the checkbox is checked?
# I can solve this by simply reversing the order of the hidden checkbox field. Like so:
<input type="hidden" value="0" name="user[is_searchable]" class="hidden"/>
<input type="checkbox" id="user_is_searchable" value="1" name="user[is_searchable]" class="checkbox" checked="checked"/>
<label for="user_is_searchable">Send me weekly motivator reports?</label>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment