Rails: Edit record in Bootstrap modal

I'm assuming you want to load the modal from a page other than the edit page.

I've got this working in my app by writing the link myself and using data-remote to specify the remote page to load. e.g

<a data-toggle="modal" data-target="#myModal" data-remote="<%= edit_ticket_path(ticket) %> #modal-edit-fields" class="btn btn-mini>Weigh out</a>

data-target specifies the modal you want to render the partial into.

edit.html.erb

<%= render 'edit_ticket_fields' %>

_edit_ticket_fields.html.erb (This could just be directly in edit.html.erb)

<div id="modal-edit-fields">
  <%= form_for @ticket, :html => { :class => 'form-horizontal' } do |f| %>      
    <div class="control-group">
      <%= f.label :customer_name, :class => 'control-label' %>
      <div class="controls">
        <%= f.hidden_field :customer_id, :class => 'text_field', :id =>"cust_id" %>
        <%= f.autocomplete_field :customer_name, autocomplete_customer_name_customers_path, :id_element => '#cust_id', :class => 'text_field ui-autocomplete-input' %>
      </div>
    </div>

Another way to do it is like so:

just create a remote link:

link_to "edit", edit_ticket_path(ticket), class: "btn btn-mini", remote: true

Then in your views, add a edit.js.erb file:

$("#myModal").html("<%= j render 'new' %>");
$('#myModal').modal('show');

and change your new.html files to _new.html