title: Rails 3: How to make a checkbox work in a form
body: <p>I'm trying to add 2 checkboxes to the edit user registration form but the attributes don't get updates when I submit the form. It says ""twitter_share"=>"1", "facebook_share"=>"1"," but this doesn't register in the database.</p>
  
  <p>What am I doing wrong??</p>
  
  <p>Form:</p>
  
  <pre><code>&lt;h2&gt;Edit &lt;%= resource_name.to_s.humanize %&gt;&lt;/h2&gt;
  
  &lt;%= form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name), :validate =&gt; true, :html =&gt; { :method =&gt; :put }, :html =&gt; {:multipart =&gt; true}) do |f| %&gt;  
    &lt;%= devise_error_messages! %&gt;
  
    &lt;p&gt;&lt;%= f.check_box_tag(:twitter_share) %&gt;
    &lt;%= f.label_tag(:twitter_share, "Share to Twitter") %&gt;&lt;/p&gt;
    &lt;p&gt;&lt;%= f.check_box_tag(:facebook_share) %&gt;
    &lt;%= f.label_tag(:facebook_share, "Share to Facebook") %&gt;&lt;/p&gt;
  
    &lt;p&gt;&lt;%= f.label :email %&gt;&lt;br /&gt;
    &lt;%= f.text_field :email %&gt;&lt;/p&gt;
    &lt;p&gt;&lt;%= f.label :name %&gt;&lt;br /&gt;
    &lt;%= f.text_field :name %&gt;&lt;/p&gt;
    &lt;p&gt;&lt;%= f.label :username %&gt;&lt;br /&gt;
    &lt;%= f.text_field :username %&gt;&lt;/p&gt;
    &lt;p&gt;&lt;%= f.label :bio %&gt;&lt;br /&gt;
    &lt;%= f.text_field :bio %&gt;&lt;/p&gt;
    &lt;p&gt;&lt;strong&gt;In order to change password:&lt;/strong&gt;&lt;/p&gt;
    &lt;p&gt;&lt;%= f.label :password %&gt; &lt;i&gt;(leave blank if you don't want to change it)&lt;/i&gt;&lt;br /&gt;
    &lt;%= f.password_field :password %&gt;&lt;/p&gt;
    &lt;p&gt;&lt;%= f.label :password_confirmation %&gt;&lt;br /&gt;
    &lt;%= f.password_field :password_confirmation %&gt;&lt;/p&gt;
    &lt;p&gt;&lt;%= f.label :current_password %&gt; &lt;i&gt;&lt;/i&gt;&lt;br /&gt;
    &lt;%= f.password_field :current_password %&gt;&lt;/p&gt;
    &lt;p&gt;&lt;strong&gt;---------------------------&lt;/strong&gt;&lt;/p&gt;
    &lt;strong&gt;Avatar&lt;/strong&gt;&lt;/br /&gt;
    &lt;div class="avatar"&gt;
     &lt;%= image_tag(@user.avatar_url(:avatartiny).to_s) if @user.avatar? %&gt;
     &lt;%= f.file_field :avatar %&gt;
     &lt;%= f.hidden_field :avatar_cache %&gt;&lt;br /&gt;
    &lt;/div&gt;&lt;br /&gt;
    &lt;p&gt;&lt;%= f.submit "Update" %&gt;&lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>User model:</p>
  
  <pre><code>  attr_accessible :email, :password, :password_confirmation, 
   :remember_me, :name, :avatar, :username, :bio, :twitter_share, :facebook_share
  </code></pre>
  
  <p>Log of form submit:</p>
  
  <pre><code>Started POST "/users" for 127.0.0.1 at 2011-06-17 13:00:48 -0700
    Processing by RegistrationsController#update as HTML
    Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"UVzD3cczDsHlBC9uRpDA+1kkIwV5OL9r6jlH4egbwVI=", "twitter_share"=&gt;"1", "facebook_share"=&gt;"1", "user"=&gt;{"email"=&gt;"example@gmail.com", "name"=&gt;"Example user", "username"=&gt;"Example", "bio"=&gt;"", "password"=&gt;"[FILTERED]", "password_confirmation"=&gt;"[FILTERED]", "current_password"=&gt;"[FILTERED]", "avatar_cache"=&gt;""}, "commit"=&gt;"Update"}
    User Load (1.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
    CACHE (0.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
  WARNING: Can't mass-assign protected attributes: current_password, avatar_cache
    SQL (0.2ms)  SELECT 1 FROM "users" WHERE (LOWER("users"."email") = LOWER('example@gmail.com')) AND ("users".id &lt;&gt; 2) LIMIT 1
    SQL (0.2ms)  SELECT COUNT(*) FROM "authentications" WHERE ("authentications".user_id = 2)
    SQL (0.1ms)  SELECT 1 FROM "users" WHERE ("users"."username" = 'Example') AND ("users".id &lt;&gt; 2) LIMIT 1
    CACHE (0.0ms)  SELECT 1 FROM "users" WHERE ("users"."username" = 'Example') AND ("users".id &lt;&gt; 2) LIMIT 1
    Slug Load (0.4ms)  SELECT "slugs".* FROM "slugs" WHERE ("slugs".sluggable_id = 2 AND "slugs".sluggable_type = 'User') ORDER BY id DESC LIMIT 1
    AREL (0.3ms)  UPDATE "users" SET "bio" = '', "encrypted_password" = '$2a$10$hu1TyBa.75o6rlfx9GF3herU15Jl87nKxmT9i3h6erCHFX20.2fze', "updated_at" = '2011-06-17 20:00:48.822900' WHERE "users"."id" = 2
  Redirected to http://localhost:3000/
  Completed 302 Found in 372ms
  </code></pre>