Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7172417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:36:41+00:00 2026-05-28T15:36:41+00:00

I have a few checkboxes that submit and change an attribute’s value on my

  • 0

I have a few checkboxes that submit and change an attribute’s value on my profile. The attribute was created as a boolean with :default => true. For every other checkbox I set up like this, the attribute’s value is either true/false. However this one checkbox is either true or nil.

Despite setting things up the same, how is that possible? I need the form to only change the value to either true or false. Not nil. Can anyone help me out?

Here’s the migration that adds the column in my Profiles table:

class AddAccessItemsToProfiles < ActiveRecord::Migration
  def self.up
    add_column :profiles, :access_items, :boolean, :default => true
  end

  def self.down
    remove_column :profiles, :access_items, :boolean, :default => nil
  end
end

(Before I go on, I notice the self.down is :default => nil, but I have that in the other migrations that work. Plus I didn’t think that would cause an issue.)

Here is my Controller action to update the value:

def access_items_settings
  if current_user.profile.update_attributes(:access_items => params[:access_items])
    redirect_to settings_path
  else
    redirect_to settings_path, :notice => 'Oops, something went wrong. Please try again.'
  end
end

Here is the form I submit:

<%= form_tag(access_items_settings_path, :method => :put) do %>
  <p class="setting"><%= check_box_tag(:access_items, 1, @user.profile.access_items ? true : false) %>
  &nbsp;This lets your items be accessed.
  <br><span class="indentClarify">(Some details.)</span></br></p>
<% end %>

(I removed the extra br, p, span, but that did nothing.)

And finally the jQuery:

$(function(){
    $(':checkbox').live('click',function() {
        $(this).closest('form').submit();
    });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:36:42+00:00Added an answer on May 28, 2026 at 3:36 pm

    This has nothing to do with the database default value.

    When a check box is unchecked the browse sends no value at all so params[:access_items] is null and that is what gets saved in the database (since your column allows nulls). The rails check_box helper (unlike check_box_tag) uses a hidden field so that an unchecked box also submits a value. You might want to use the same technique.

    I don’t know what is different about those other checkboxes so can’t comment on those.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an app that has a few checkboxes in the settings and then
We have few components like libraries dlls When initially created I ran the following
In almost all of my projects I have few files that are project wide
I have a few checkboxes values of which are posted to action, and when
I have a web form with about 15 checkboxes that users may check 0
I'm trying to create a fairly simple form that has a few checkboxes and
I wrote a custom PreferenceDialog that includes two TimePickers, an EditText, a few CheckBoxes,
I have a form that contains a bunch of checkboxes. Before submitting the form,
I dynamically load in a few li's that have a label and a checkbox
I have a few checkboxes on top of my webpage which correspond to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.