Updated

app/controllers/admin / government_response_controller.rb

B
45 lines of codes
6 methods
3.7 complexity/method
13 churn
22.23 complexity
28 duplications
class Admin::GovernmentResponseController < Admin::AdminController
  1. Admin::GovernmentResponseController assumes too much for instance variable '@government_response'
  2. Admin::GovernmentResponseController assumes too much for instance variable '@petition'
  3. Admin::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/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? EmailThresholdResponseJob.run_later_tonight(petition: @petition) message = :email_sent_overnight else message = :government_response_updated end redirect_to [:admin, @petition], notice: message else render 'admin/petitions/show' end end private def fetch_petition @petition = 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(:government_response).permit(:responded_on, :summary, :details) end def send_email_to_petitioners? params.key?(:save_and_email) end end