0

I need to refactor this private method. Codeclimate is giving me a error msj because the line of the params is too long. How can i refactor it?

def base_plan_params
    params[:base_plan][:debit_date_attributes]&.merge!(
      account_id: current_account.id,
      _destroy: params[:base_plan][:debit_date_attributes][:date_type].blank?,
    )
    params.require(:base_plan).permit(
      :code,
      :cover,
      :name,
      :products,
      :pricing_model,
      :metered,
      debit_date_attributes: %i[id account_id date_type value _destroy],
    )
  end```

1 Answer 1

1

making an assumption here about which CodeClimate "too long" error is being triggered, as you didn't clarify.

You could form the permitted params into an array, like this:

permitted_params = [:code, :cover, :name, :products, :pricing_model, :metered]
params.require(:base_plan).
       permit(*permitted_params, 
              debit_date_attributes: %i[id account_id_data_type value _destroy],)

Personally I wouldn't bother, but if the CodeClimate warning troubles you, then this solution would probably work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Les, yes i didn't give too much context, but you have answered my question. The error msj was: line too long, consider refactor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.