Rails:在 Bootstrap 模式中编辑记录 [英] Rails: Edit record in Bootstrap modal
问题描述
我正在尝试在 Rails 中使用 Bootstrap 模态来编辑记录,但我无法将模态范围限定为当前记录
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
静态链接是
<%= link_to "Weigh Out", edit_ticket_path(ticket), "data-toggle" => "modal", :class => 'btn btn-mini', :id => 'edit_modal_link', "data-toggle" => "modal" %>
我确实需要调用 id/edit 上的模式,这是票号,但无法将其链接到表中的选定记录.
I really need to call the modal on id/edit which is the ticket number but cannot get it to link to the selected record in the table.
有什么想法吗?
或者渲染一个部分,但必须使用可用的票证来调用部分票证?
Or render a partial but the partial must be called with the ticket available to it is scoped correctly to the ticket we need to edit?
我的部分看起来像
<%= 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>
需要在Modal中渲染,
Which need to render in Modal,
推荐答案
另外一种方法是这样的:
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
然后在你的视图中,添加一个edit.js.erb文件:
Then in your views, add a edit.js.erb file:
$("#myModal").html("<%= j render 'new' %>");
$('#myModal').modal('show');
并将您的 new.html 文件更改为 _new.html
and change your new.html files to _new.html
这篇关于Rails:在 Bootstrap 模式中编辑记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!