Simplify URL to destroy a booth assignment

We can find the booth through the booth assignment, so we don't need to
pass it in the URL.

Since the parameter is in the URL and not sent through a form, we can
also use `params[:poll_id]` directly, and so we can reuse the
`load_poll` method.
This commit is contained in:
Javi Martín
2020-06-08 22:56:23 +02:00
parent 9424db4de0
commit f76930aab6
2 changed files with 4 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController
before_action :load_poll, except: [:create, :destroy] before_action :load_poll, except: [:create]
def index def index
@booth_assignments = @poll.booth_assignments.includes(:booth).order("poll_booths.name") @booth_assignments = @poll.booth_assignments.includes(:booth).order("poll_booths.name")
@@ -36,9 +36,8 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController
end end
def destroy def destroy
@poll = Poll.find(booth_assignment_params[:poll_id]) @booth_assignment = @poll.booth_assignments.find(params[:id])
@booth = Poll::Booth.find(booth_assignment_params[:booth_id]) @booth = @booth_assignment.booth
@booth_assignment = ::Poll::BoothAssignment.find(params[:id])
@booth_assignment.destroy! @booth_assignment.destroy!

View File

@@ -12,7 +12,7 @@
</td> </td>
<td> <td>
<%= link_to t("admin.booth_assignments.manage.actions.unassign"), <%= link_to t("admin.booth_assignments.manage.actions.unassign"),
admin_poll_booth_assignment_path(@poll, booth_assignment, booth_id: booth.id), admin_poll_booth_assignment_path(@poll, booth_assignment),
method: :delete, method: :delete,
remote: true, remote: true,
title: t("admin.booth_assignments.manage.actions.unassign"), title: t("admin.booth_assignments.manage.actions.unassign"),