我一直在使用link_to删除所有索引文件中的路由时遇到麻烦,无法弄明白。我最近将所有内容命名为:backend。
网址的结构类似于此后端/ membercontacts / 1 / memberlistings /
就像form_for一样,我试图给它一个网址或正确的路径无济于事。这是在命名空间之前所做的工作。
<%= link_to 'Delete', [memberlisting.membercontact, memberlisting], method: :delete, data: { confirm: 'Are you sure? This will also remove this listing from the online directories.' }, :class => "btn btn-danger btn-sm" %>
补充视图:views / backend / memberlistings / index.html.erb
<div class="card">
<div class="card-block">
<h4 class="card-title">Member Listing Index</h4>
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Full Name</th>
<th>Company Name</th>
<th>City</th>
<th>Province</th>
<th>Phone Number</th>
<th>Email</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @memberlistings.each do |memberlisting| %>
<tr>
<td><%= memberlisting.mlcontactname %></td>
<td><%= memberlisting.mlcompanyname %></td>
<td><%= memberlisting.mlcity %></td>
<td><%= memberlisting.mlprovince %></td>
<td><%= memberlisting.mlphone %></td>
<td><%= memberlisting.mlemail %></td>
<td>
<div class="btn-group" role="group" aria-label="Member Listings Group">
<%= link_to 'Details', backend_membercontact_memberlisting_path(memberlisting.membercontact, memberlisting), :class => "btn btn-primary btn-sm" %>
<%= link_to 'Edit', edit_backend_membercontact_memberlisting_path(memberlisting.membercontact, memberlisting), :class => "btn btn-primary btn-sm" %>
<%= link_to 'Delete', [memberlisting.membercontact, memberlisting], method: :delete, data: { confirm: 'Are you sure? This will also remove this listing from the online directories.' }, :class => "btn btn-danger btn-sm" %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= link_to 'New Member Listing', new_backend_membercontact_memberlisting_path, :class => "btn btn-primary btn-sm" %>
</div>
</div>
如果需要其他信息,请与我们联系。
答案 0 :(得分:1)
在我看来,你似乎错过了那里的backend_membercontact_memberlisting_path ...试试这个:
<%= link_to 'Delete', backend_membercontact_memberlisting_path(memberlisting.membercontact, memberlisting), method: :delete, data: { confirm: 'Are you sure? This will also remove this listing from the online directories.' }, :class => "btn btn-danger btn-sm" %>