title: Bootstrap modal inside a ruby on rails form
body: <p>I have a profile edit page and would like to have two modals within the edit form. One modal will open a newsletter preference section of the form (as seen below)
  The other modal will open a password field to enter and save the changes. Both modals are inside the <code>&lt;% end %&gt;</code> tags of the form.</p>
  
  <p>They didn't open, changed some code, now <code>undefined local variable or method 'f'</code> inside <code>_passwordModal.html.erb</code></p>
  
  <p>Edit page html:</p>
  
  <pre><code>&lt;div class="wellington center"&gt;
  &lt;%= form_for :users, url: user_path(@user), method: :patch do |f| %&gt;
  
  &lt;div class="row"&gt;
    &lt;div class="col-md-6 left"&gt;
      &lt;div class="form-group"&gt;
        &lt;%= f.text_field :username, :required =&gt; false, disabled: true, placeholder: "#{@user.username}", class: 'form-control', id: 'editUsername' %&gt;
        &lt;%= f.text_field :first_last_name, placeholder: "#{@user.first_last_name}", class: 'form-control' %&gt;
        &lt;%= f.email_field :email, placeholder: "#{@user.email}", class: 'form-control' %&gt; &lt;!-- id: "inputEmail" --&gt;
      &lt;/div&gt;
      &lt;div class="news-pref"&gt;
        &lt;a href="#mailPref" role="button" class="btn btn-xs btn-warning" data-toggle="modal"&gt;Email Preferences&lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;div class="col-md-6 left"&gt;
      &lt;label id="outlineLabel" for="birthday"&gt;Birth Date&lt;/label&gt;
      &lt;form class="form-inline" id="birthday"&gt;
        &lt;div class="form-group"&gt;
          &lt;input type="text" class="form-control" id="inputMonth" placeholder="Month"&gt;
        &lt;/div&gt;
      &lt;/form&gt;
      &lt;form class="form-inline"&gt;
        &lt;div class="form-group"&gt;
          &lt;input type="text" class="form-control" id="inputDay" placeholder="Day"&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
          &lt;input type="text" class="form-control" id="inputYear" placeholder="Year"&gt;
        &lt;/div&gt;
      &lt;/form&gt;
  
      &lt;label id="outlineLabel" for="country"&gt;Location&lt;/label&gt;
      &lt;form class="form-inline" id="country"&gt;
        &lt;div class="form-group"&gt;
          &lt;input type="text" class="form-control" placeholder="Country"&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
          &lt;input type="text" class="form-control" placeholder="State / Prov. / Region"&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
          &lt;input type="text" class="form-control" placeholder="City"&gt;
        &lt;/div&gt;
      &lt;/form&gt;
    &lt;/div&gt;
  
  &lt;/div&gt;
    &lt;a href="#passModal" role="button" class="btn btn-success save" data-toggle="modal"&gt;Save Changes&lt;/a&gt;
    &lt;% render 'newsPref' %&gt;
    &lt;% render 'passwordModal' %&gt;
    &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>_newsPref.html.erb view:</p>
  
  <pre><code>&lt;div class="modal hide fade" id="mailPref" tabindex="-1" role="dialog" aria-labelledby="mailPrefLabel"&gt;
    &lt;div class="modal-dialog" role="document"&gt;
      &lt;div class="modal-content"&gt;
        &lt;div class="modal-header"&gt;
          &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
          &lt;h4 class="modal-title" id="mailPrefLabel"&gt;Email Preferences&lt;/h4&gt;
        &lt;/div&gt;
        &lt;div class="modal-body"&gt;
  
          &lt;p&gt;&lt;em&gt;How would you like to receive our newsletter?&lt;/em&gt;&lt;/p&gt;
          &lt;div class="checkbox"&gt;
            &lt;%= f.label :newsletter, class: "checkbox inline" do %&gt;
              &lt;%= f.check_box :newsletter %&gt;
              &lt;span&gt;By checking this box, you agree to get emails from us, via our newsletter as well as our priority announcements.&lt;/span&gt;
            &lt;% end %&gt;
          &lt;/div&gt;
          &lt;p&gt;We typically send out a weekly newsletter to provide information on what we uploaded, wrote about, and tips that were all published during the week.&lt;/p&gt;
          &lt;div class="checkbox"&gt;
            &lt;%= f.label :less_mail, class: "checkbox inline" do %&gt;
              &lt;%= f.check_box :less_mail %&gt;
              &lt;span&gt;1 Newsletter per month: if you feel overwhelmed by weekly updates, don't worry!. By checking this box we'll cut back on the ammount we send to you, but still give you the opportunity to see what happend during the previous month.&lt;/span&gt;
            &lt;% end %&gt;
          &lt;/div&gt;
          &lt;p&gt;&lt;span class="text-muted"&gt;Priority anouncements may include sweepstakes, contests or other information that is "time-critial". These announcements are not always included in the newsletter and may be sent in addition to your newsletter preference.&lt;/span&gt;&lt;/p&gt;
          &lt;div class="checkbox"&gt;
            &lt;%= f.label :newsletter, class: "checkbox inline" do %&gt;
              &lt;%= f.check_box :newsletter %&gt;
              &lt;span&gt;To opt-out of recieving any future newsletters, go ahead and check this box. We hope to see you come back soon!&lt;/span&gt;
            &lt;% end %&gt;
            &lt;p&gt;&lt;em&gt;psst... By opting out you might miss out on some sweet discounts, contests and givaways!&lt;/em&gt;&lt;/p&gt;
          &lt;/div&gt;
  
        &lt;/div&gt;
        &lt;div class="modal-footer"&gt;
          &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
          &lt;button type="button" class="btn btn-success" data-dismiss="modal" data-toggle="modal" data-target="#passModal"&gt;Save Changes&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>_passwordModal.html.erb view:</p>
  
  <pre><code>&lt;div class="modal hide fade" id="passModal" tabindex="-1" role="dialog" aria-labelledby="passModalLabel"&gt;
    &lt;div class="modal-dialog" role="document"&gt;
      &lt;div class="modal-content"&gt;
        &lt;div class="modal-header"&gt;
          &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
          &lt;h4 class="modal-title" id="passModalLabel"&gt;Confirm Password&lt;/h4&gt;
        &lt;/div&gt;
        &lt;div class="modal-body"&gt;
  
          &lt;p&gt;&lt;em&gt;Please enter your password to confirm changes.&lt;/em&gt;&lt;/p&gt;
          &lt;div class="form-group"&gt;
            &lt;%= f.password_field :password, :placeholder =&gt; "Password", class: "form-control center" %&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="modal-footer"&gt;
          &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Cancel&lt;/button&gt;
          &lt;% f.submit "Save changes", class: "btn btn-success" %&gt;
        &lt;/div&gt;
  
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>.JS for swapping modals:</p>
  
  <pre><code>$("#edit-switch").click(function() {
  $("#mailPref").modal('hide');
  $("#passModal").modal('show');
  });
  </code></pre>