Freika/dawarich · warning · ActionController::ParameterMissing

longitude

Error message

longitude

What it means

The third strong-parameters gate: photon[longitude] blank raises ActionController::ParameterMissing with message 'longitude', rendered as json {error: 'longitude'} with 422 by the controller's rescue. Blank means missing, nil, or empty string; range validation of the parsed value happens separately at line 30.

Source

Thrown at app/controllers/api/v1/visits/select_place_controller.rb:25

    render json: serialize_place(place), status: :created
  rescue ActiveRecord::RecordNotFound
    render json: { error: I18n.t('controllers.api.v1.visits.select_place.visit_not_found') }, status: :not_found
  rescue ActiveRecord::RecordInvalid, ActionController::ParameterMissing => e
    render json: { error: e.message }, status: :unprocessable_entity
  end

  private

  def photon_params
    params.require(:photon).permit(
      :name, :latitude, :longitude,
      :osm_id, :osm_type, :osm_key, :osm_value,
      :city, :country, :street, :housenumber, :postcode,
      geodata: {}
    ).tap do |p|
      raise ActionController::ParameterMissing, :name      if p[:name].blank?
      raise ActionController::ParameterMissing, :latitude  if p[:latitude].blank?
      raise ActionController::ParameterMissing, :longitude if p[:longitude].blank?

      lat = p[:latitude].to_f
      lon = p[:longitude].to_f
      raise ActionController::ParameterMissing, :latitude  unless lat.between?(-90, 90)
      raise ActionController::ParameterMissing, :longitude unless lon.between?(-180, 180)
    end
  end

  def serialize_place(place)
    tags = place.tags.to_a
    first_tag = tags.first

    {
      id: place.id,
      name: place.name,
      latitude: place.lat,
      longitude: place.lon,
      source: place.source,

View on GitHub (pinned to 97fad417c5)

Solutions

  1. Send photon[longitude] nested inside the photon object, non-empty
  2. Verify the whole payload shape: {photon: {name:, latitude:, longitude:, ...}} - nesting errors hit longitude first if it is the last key built
  3. Validate the place candidate has coordinates before enabling the select action in the UI
  4. Map the {error: 'longitude'} 422 to a 'Longitude is required' message

Example fix

// before
body: JSON.stringify({ name: 'Home', latitude: 52.5, longitude: 13.4 })

// after
body: JSON.stringify({ photon: { name: 'Home', latitude: 52.5, longitude: 13.4 } })
Defensive patterns

Strategy: validation

Validate before calling

function hasLongitude(p) {
  return p != null && p.longitude !== undefined && p.longitude !== null && String(p.longitude).trim() !== ''
}

Prevention

When it happens

Trigger: POST /api/v1/visits/select_place with photon lacking longitude, longitude: '' or null, or longitude nested at the wrong level (outside the photon object) so params.require(:photon) never sees it.

Common situations: Flattened payloads sending {name, latitude, longitude} at the top level instead of nested under photon, serialization code dropping null coords, partial place objects from a search index that lack coordinates.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of Freika/dawarich@97fad417c5 (2026-08-21). Data as JSON: /api/errors/343985939a66fb74. Report an issue: GitHub.