Updated

app/controllers/admin/archived / government_response_controller.rb

B
45 lines of codes
6 methods
3.9 complexity/method
13 churn
23.5 complexity
28 duplications
class Admin::Archived::GovernmentResponseController < Admin::AdminController
  1. Admin::Archived::GovernmentResponseController assumes too much for instance variable '@government_response'
  2. Admin::Archived::GovernmentResponseController assumes too much for instance variable '@petition'
  3. Admin::Archived::GovernmentResponseController has no descriptive comment
before_action :fetch_petition before_action :fetch_government_response rescue_from ActiveRecord::RecordNotUnique do @government_response = @petition.government_response(true) and update end def show render 'admin/archived/petitions/show' end def update
  1. Similar code found in 3 nodes Locations: 0 1 2
if @government_response.update(government_response_params) if send_email_to_petitioners? ::Archived::EmailThresholdResponseJob.run_later_tonight(petition: @petition) message = :email_sent_overnight else message = :government_response_updated end redirect_to admin_archived_petition_url(@petition), notice: message else render 'admin/archived/petitions/show' end end private def fetch_petition @petition = ::Archived::Petition.moderated.find(params[:petition_id]) end def fetch_government_response @government_response = @petition.government_response || @petition.build_government_response end def government_response_params params.require(:archived_government_response).permit(:responded_on, :summary, :details) end def send_email_to_petitioners? params.key?(:save_and_email) end end