From 667c2c82b505682e478ce52d2b60335b1f30fb5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 17 Sep 2018 17:36:41 +0200 Subject: [PATCH] Use toggle_select action for legislation proposals The `update` action is usually expected to behave the same way it does everywhere else, which is updating a record using the `params` hash. The name `toggle_select` comes from the name we use in a similar situation for budget investments. --- .../admin/legislation/proposals_controller.rb | 15 +++++---------- .../proposals/_select_proposal.html.erb | 6 +++++- config/routes/admin.rb | 4 +++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/controllers/admin/legislation/proposals_controller.rb b/app/controllers/admin/legislation/proposals_controller.rb index bd46d28fe..0c3116cd7 100644 --- a/app/controllers/admin/legislation/proposals_controller.rb +++ b/app/controllers/admin/legislation/proposals_controller.rb @@ -9,15 +9,10 @@ class Admin::Legislation::ProposalsController < Admin::Legislation::BaseControll @proposals = @proposals.send("sort_by_#{@current_order}").page(params[:page]) end - def update - @proposal.selected = !@proposal.selected - - if @proposal.save - notice = t('admin.legislation.proposals.update.notice') - else - notice = t('admin.legislation.proposals.update.error') - end - redirect_to admin_legislation_process_proposals_path, notice: notice + def toggle_selection + @proposal.toggle :selected + @proposal.save! + redirect_to admin_legislation_process_proposals_path, + notice: t('admin.legislation.proposals.update.notice') end - end \ No newline at end of file diff --git a/app/views/admin/legislation/proposals/_select_proposal.html.erb b/app/views/admin/legislation/proposals/_select_proposal.html.erb index 9a40b2c2f..6749c5904 100644 --- a/app/views/admin/legislation/proposals/_select_proposal.html.erb +++ b/app/views/admin/legislation/proposals/_select_proposal.html.erb @@ -5,4 +5,8 @@ button_text = t("admin.legislation.proposals.index.select") clas = 'button hollow expanded' end %> -<%= link_to button_text, admin_legislation_process_proposal_path(proposal.process, proposal), method: 'PUT', class: clas %> + +<%= link_to button_text, + toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal), + method: :patch, + class: clas %> diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 335d389d0..bd296658d 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -194,7 +194,9 @@ namespace :admin do namespace :legislation do resources :processes do resources :questions - resources :proposals + resources :proposals do + member { patch :toggle_selection } + end resources :draft_versions end end