Home > Mobile >  Managing json as params in Rails 5
Managing json as params in Rails 5

Time:09-16

In my Rails 5 app I've got following params inside one of the controllers:

  def batch_create_appointments_params
    params.permit(_json: ["details": %i[checkInDateTime checkOutDateTime waiting], "vehicle": %i[licence_plate vin brand model], "customer": %i[first_name last_name], "contact": %i[contact_method email phone], jobs: [:jobId, { labor: [:description], menus: [:description] }]])
  end

As you see it is pretty long json params. I wonder if it is a normal approach to have such long params? especially when it comes to Rubocop Layout/LineLength settings which I've set to Max: 120. Is there any way to split these params? or should I disable the Layout/LineLength in rubocop for those lines?

CodePudding user response:

I'd suggest this formatting

  def batch_create_appointments_params
    params.permit(_json: [
      details: %i[checkInDateTime checkOutDateTime waiting],
      vehicle: %i[licence_plate vin brand model],
      customer: %i[first_name last_name],
      contact: %i[contact_method email phone],
      jobs: [:jobId, { labor: [:description], menus: [:description] }]
    ])
  end
  • Related