authors can retire proposals now

This commit is contained in:
Juanjo Bazán
2016-04-22 14:42:49 +02:00
parent be011a10dc
commit 58a5e2a283
11 changed files with 174 additions and 10 deletions

View File

@@ -35,6 +35,17 @@ class ProposalsController < ApplicationController
set_proposal_votes(@proposal)
end
def retire
if valid_retired_params? && @proposal.update(retired_params.merge(retired_at: Time.now))
redirect_to proposal_path(@proposal), notice: t('proposals.notice.retired')
else
render action: :retire_form
end
end
def retire_form
end
def vote_featured
@proposal.register_vote(current_user, 'yes')
set_featured_proposal_votes(@proposal)
@@ -51,6 +62,16 @@ class ProposalsController < ApplicationController
params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :tag_list, :terms_of_service, :captcha, :captcha_key, :geozone_id)
end
def retired_params
params.require(:proposal).permit(:retired_reason, :retired_explanation)
end
def valid_retired_params?
@proposal.errors.add(:retired_reason, I18n.t('errors.messages.blank')) if params[:proposal][:retired_reason].blank?
@proposal.errors.add(:retired_explanation, I18n.t('errors.messages.blank')) if params[:proposal][:retired_explanation].blank?
@proposal.errors.empty?
end
def resource_model
Proposal
end