We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
74 lines
2.3 KiB
Ruby
74 lines
2.3 KiB
Ruby
class Legislation::ProposalsController < Legislation::BaseController
|
|
include CommentableActions
|
|
include FlagActions
|
|
include ImageAttributes
|
|
|
|
before_action :parse_tag_filter, only: :index
|
|
before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary]
|
|
before_action :load_geozones, only: [:edit, :map, :summary]
|
|
|
|
before_action :authenticate_user!, except: [:index, :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[confidence_score created_at], only: :index
|
|
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 index_customization
|
|
load_successful_proposals
|
|
load_featured unless @proposal_successful_exists
|
|
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
|
|
|
|
def load_successful_proposals
|
|
@proposal_successful_exists = Legislation::Proposal.successful.exists?
|
|
end
|
|
end
|