Skip to content

Support nested attribute names for validation error messages #1933

Open
@amrrbakry

Description

@amrrbakry

Hello,

I'm trying to override a nested attribute's name that gets show in the validation message, but it doesn't seem possible for nested params

I want to override registration[total_capacity] attribute name:

my params:

params :sessions_params do
  optional :registration_allowed, type: Boolean, desc: 'registration allowed for session?'
  optional :registration, type: Hash, desc: 'session registration settings' do
    requires :total_capacity, type: Integer, desc: 'session registration total capacity', message: :name_required
    requires :waiting_list_enabled, type: Boolean, desc: 'is session registration waiting list enabled?'
  end
end

en.yml

en:
  grape:
    errors:
      format: ! '%{attributes} %{message}'
      messages:
        name_required: 'must be present'
      attributes:
        registration:
          total_capacity: 'Total capacity'

expected error message if total capacity is not sent:

"Total capacity must be present"

actual error message:

"registration[total_capacity] must be present"

is this not possible or is there a problem with my code?

using grape 0.16.2, ruby 2.3.3, rails 4.2

thanks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions