Rails:在Bootstrap模式中编辑记录
我正在尝试在Rails中使用Bootstrap模式来编辑记录,但我无法将模式范围扩展到当前记录
静态链接是
"modal", :class => 'btn btn-mini', :id => 'edit_modal_link', "data-toggle" => "modal" %>
我真的需要在id / edit上调用模式,这是票号,但是无法将其链接到表中的选定记录。
有任何想法吗?
或渲染部分,但必须使用可用的票证调用部分,它的范围是否正确到我们需要编辑的票证?
我的部分看起来像
{ :class => 'form-horizontal' } do |f|%> 'control-label' %> 'text_field', :id =>"cust_id" %> '#cust_id', :class => 'text_field ui-autocomplete-input' %>
哪个需要在Modal中渲染,
另一种方法是这样的:
只需创建一个远程链接:
link_to "edit", edit_ticket_path(ticket), class: "btn btn-mini", remote: true
然后在您的视图中,添加edit.js.erb文件:
$("#myModal").html("<%= j render "new"%>"); $('#myModal').modal('show');
并将您的edit.html和new.html文件更改为_new.html和edit.html
我假设您要从编辑页面以外的页面加载模态。
通过自己编写链接并使用data-remote
指定要加载的远程页面,我已经在我的应用程序中工作了。 例如
<%= form_for @ticket, :html => { :class => 'form-horizontal' } do |f| %> <%= f.label :customer_name, :class => 'control-label' %> <%= 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' %>