vendredi 10 juin 2016

Using Bootstrap modals in Ruby on Rails


I'm attempting to render a rails view _form.html.erb in a bootstrap modal. I'm able to render the view another page but it isn't the page I would like.

I also want the view to render in the modal when <%= link_to 'New Client', new_client_path, class: "btn btn-primary" %> is clicked. in index.html.erb

It's just the basic modal:

 <!-- Large modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Large modal</button>

<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      ...
    </div>
  </div>
</div>

assets/javascripts/modal.js used for modal

$('#myModal').on('shown.bs.modal', function () {
  $('#myInput').focus()
})

_form.html.erb

  <%=form_for(@client, html: {class: "pure-form pure-form-stacked", multipart:true}) do |f| %>
    <% if @client.errors.any? %>
        <div id="error_explanation">
            <h2><%= pluralize(@client.errors.count, "error") %> prohibited this client from being saved:</h2>
            <ul>
                <% @client.errors.full_messages.each do |message| %>
                    <li>
                        <%=message %>
                    </li>
                    <% end %>
            </ul>
        </div>
        <% end %>
            <!-- beginning of form code -->
             ...
            <!-- end of form code -->
                </fieldset>
                <div class="actions">
                    <%=f .submit class: "btn btn-primary" %>
                        <%=link_to 'Cancel', clients_path, class: "btn btn-danger" %>
                </div>
                <% end %>
            </form>

Aucun commentaire:

Enregistrer un commentaire