Reputation: 23
in my route.rb I have this
Rails.application.routes.draw do
resources :cars do
resource :payments
end
end
However, in my destroy link for payments. the URL generated is
http://localhost:3000/cars/9/payments.11
Below is my code.
<% @car.payments.each do |p| %>
<tr>
<td><%= p.date %></td>
<td><%= p.profit %></td>
<td><%= p.remark %></td>
<td><%= link_to 'Delete', car_payments_path(@car, @p) ,
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
Please advice. Thank you in advanced.
Upvotes: 1
Views: 920
Reputation: 3196
To delete a payment in a car, the route should be a member route , call it like this:
car_payment_path(@car, @p)
car_payments_path(..)
was a collection route of payments.
Suggest you to test at console like this:
app.car_payment_path(Car.first, Car.first.payments.first)
Upvotes: 1
Reputation: 1652
Looks like this is a pluralization error. Try
cars_payment_path
instead of
car_payments_path
Upvotes: 1