Files
nairobi/app/controllers/legislation/proposals_controller.rb
Javi Martín 0bacd5baf3 Remove unused legislation proposals index action
The `legislation_proposals#index` action was never used because it used
the same URL as `legislation_processes#proposals`.

In commit 702bfec24 we removed the view, but we forgot to remove the
controller action, the route, and some partials which were rendered from
the index view.
2022-02-21 18:47:13 +01:00

63 lines
2.0 KiB
Ruby

class Legislation::ProposalsController < Legislation::BaseController
include CommentableActions
include FlagActions
include ImageAttributes
before_action :load_categories, only: [:new, :create, :edit, :map, :summary]
before_action :load_geozones, only: [:edit, :map, :summary]
before_action :authenticate_user!, except: [:show, :map, :summary]
load_and_authorize_resource :process, class: "Legislation::Process"
load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process
invisible_captcha only: [:create, :update], honeypot: :subtitle
has_orders %w[most_voted newest oldest], only: :show
helper_method :resource_model, :resource_name
respond_to :html, :js
def show
super
legislation_proposal_votes(@process.proposals)
@document = Document.new(documentable: @proposal)
if request.path != legislation_process_proposal_path(params[:process_id], @proposal)
redirect_to legislation_process_proposal_path(params[:process_id], @proposal),
status: :moved_permanently
end
end
def create
@proposal = Legislation::Proposal.new(proposal_params.merge(author: current_user))
if @proposal.save
redirect_to legislation_process_proposal_path(params[:process_id], @proposal), notice: I18n.t("flash.actions.create.proposal")
else
render :new
end
end
def vote
@proposal.register_vote(current_user, params[:value])
legislation_proposal_votes(@proposal)
end
private
def proposal_params
params.require(:legislation_proposal).permit(:legislation_process_id, :title,
:summary, :description, :video_url, :tag_list,
:terms_of_service, :geozone_id,
image_attributes: image_attributes,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id])
end
def resource_model
Legislation::Proposal
end
def resource_name
"proposal"
end
end