Rails: Edit record in Bootstrap modal

前端 未结 2 580
我在风中等你
我在风中等你 2021-02-09 06:07

I\'m trying to use a Bootstrap modal in Rails to edit a record, but I can\'t get the modal to scope to the current record

The static link is

<%= lin         


        
相关标签:
2条回答
  • 2021-02-09 06:31

    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

    0 讨论(0)
  • 2021-02-09 06:37

    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>
    
    0 讨论(0)
提交回复
热议问题