title: Assigning model instance attributes based on a checkbox value
body: <p>I have a user model that has <code>stage_name</code> and <code>real_name</code> string attributes. What I'd like to do is in my <code>_form.hmlt.erb</code> have a checkbox next to the real name input box that asks, <em>Real name is stage name?</em>. If checked then I'd like to assign the real name as the stage name and disable the Stage Name <code>input box with</code>real_name` real name now as its value. So far I have:</p>
  
  <p><strong>_form.html.erb</strong></p>
  
  <pre><code>&lt;%= form_for @user do |f| %&gt;
    &lt;div&gt;
      &lt;%= f.text_field :stage_name %&gt;
      &lt;%= f.text_field :stage_name %&gt; 
    &lt;/div&gt;
  
    &lt;div&gt;
      &lt;%= f.text_field :real_name %&gt;
      &lt;%= f.text_field :real_name %&gt;
  
      # Not sure how to bind my model code to this checkbox
      &lt;%= f.checkbox %&gt;
      &lt;%= f.label 'Real name is stage name?' %&gt;
    &lt;/div&gt;
  
    &lt;div&gt;
      &lt;%= f.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  
  &lt;script&gt;
    $(function() {
      $("input[type='checkbox']").click(function() {
        var $checkbox   = $(this),
            $secondForm =  $("input[type='text']").eq(2);
  
        if ($checkbox.is(":checked")) {
          $secondForm.attr("disabled", true).val("&lt;%= @user.real_name %&gt;");
        } else {
            $secondForm.attr("disabled", false).val("");
        }
      });
    )};
  &lt;/script&gt;
  </code></pre>