Files
grecia/app/controllers/dashboard/polls_controller.rb
Javi Martín 55c8fa3297 Fix obsolete respond_with_bip usage
Since we removed the `best_in_place` gem, this method doesn't exist
anymore. We're replacing it with what the method actually does.

Note the test doesn't check the poll is correctly updated. We could add
a `visit proposal_dashboard_polls_path(proposal)` before checking the
"Show results" field, but then we would enter a race condition between
this request and the AJAX request. A proper solution would be to provide
actual feedback to the user so they know the poll has been updated, and
then checking that feedback is present in the tests.
2019-05-09 19:41:04 +02:00

75 lines
1.9 KiB
Ruby

class Dashboard::PollsController < Dashboard::BaseController
helper_method :poll
def index
authorize! :manage_polls, proposal
@polls = Poll.for(proposal)
end
def new
authorize! :manage_polls, proposal
@poll = Poll.new
end
def create
authorize! :manage_polls, proposal
@poll = Poll.new(poll_params.merge(author: current_user, related: proposal,
stats_enabled: false))
if @poll.save
redirect_to proposal_dashboard_polls_path(proposal), notice: t("flash.actions.create.poll")
else
render :new
end
end
def edit
authorize! :manage_polls, proposal
end
def update
authorize! :manage_polls, proposal
respond_to do |format|
if poll.update(poll_params)
format.html { redirect_to proposal_dashboard_polls_path(proposal),
notice: t("flash.actions.update.poll") }
format.json { head :no_content }
else
format.html { render :edit }
format.json { render json: poll.errors.full_messages, status: :unprocessable_entity }
end
end
end
private
def poll
@poll ||= Poll.includes(:questions).find(params[:id])
end
def poll_params
params.require(:poll).permit(poll_attributes)
end
def poll_attributes
[:name, :starts_at, :ends_at, :description, :results_enabled, :stats_enabled,
questions_attributes: question_attributes]
end
def question_attributes
[:id, :title, :author_id, :proposal_id, :_destroy,
question_answers_attributes: question_answers_attributes]
end
def question_answers_attributes
[:id, :_destroy, :title, :description, :given_order, :question_id,
documents_attributes: documents_attributes]
end
def documents_attributes
[:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
end
end