Files
nairobi/app/controllers/admin/poll/booths_controller.rb
Javi Martín 710a1d8357 Split Poll::Booth.search in two methods
We use this method in two different scenarios. In an AJAX request, we
don't want to return every booth if the search is blank. However, in a
normal HTTP GET request, we want to return every record when the search
is empty, as we do everywhere else.

It's possible the behaviour of the AJAX call is unusual, since it
searches all booths, and not just the ones assigned to a poll. If we
changed this behaviour, we could simplify the code and remove the
`quick_search` method.
2019-10-07 14:30:39 +02:00

46 lines
851 B
Ruby

class Admin::Poll::BoothsController < Admin::Poll::BaseController
load_and_authorize_resource class: "Poll::Booth"
def index
@booths = @booths.search(params[:search])
@booths = @booths.order(name: :asc).page(params[:page])
end
def show
end
def new
end
def create
if @booth.save
redirect_to admin_booths_path, notice: t("flash.actions.create.poll_booth")
else
render :new
end
end
def edit
end
def update
if @booth.update(booth_params)
redirect_to admin_booth_path(@booth), notice: t("flash.actions.update.poll_booth")
else
render :edit
end
end
def available
@booths = Poll::Booth.available.order(name: :asc).page(params[:page])
render :index
end
private
def booth_params
params.require(:poll_booth).permit(:name, :location)
end
end