bradpotts
bradpotts

Reputation: 329

Nested Resource link_to Delete Error with Namespacing

I've been having troubles with the link_to delete routes in all my index files, can't figure it out. I recently namespaced everything to :backend.

The url is structured like this backend/membercontacts/1/memberlistings/

Like the form_for I tried to give it a url or the right path to no avail. This is what worked before namespacing everything.

<%= 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" %>

The comple view: 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>

Let me know if additional info is needed.

Upvotes: 0

Views: 24

Answers (1)

Alexandre Voyer
Alexandre Voyer

Reputation: 819

Seems to me like you're missing the backend_membercontact_memberlisting_path in there... try this:

<%= 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" %>

Upvotes: 1

Related Questions