Skip to content

Ability to explicitly pass in the error to be shown #324

@alphamarket

Description

@alphamarket

I have a huge complicated form which contains with multiple subforms(in some loops) with custom namings and etc... I process data and validate each model and extract the following error structure:

@errors = {
    :spec => {
        :"1" => {
            :section => {
                :"6" => {
                    :errors => #<ActiveModel::Errors:0x007f0d807811c8 @base=#<BuildDetail id: nil, admin_sections_id: 6, admin_specs_id: 1, value: nil, created_at: nil, updated_at: nil, options: {"admin_stuffs"=>{"id"=>"2"}}>, @messages={:value=>["needs to be filled!"]}, @details={:value=>[{:error=>:blank}]}>
                },
                :"7" => {
                    :errors => #<ActiveModel::Errors:0x007f0d89d0cb98 @base=#<BuildDetail id: nil, admin_sections_id: 7, admin_specs_id: 1, value: nil, created_at: nil, updated_at: nil, options: {"admin_stuffs"=>{"id"=>"1"}}>, @messages={:value=>["needs to be filled!"]}, @details={:value=>[{:error=>:blank}]}>
                },
                :"8" => {
                    :errors => #<ActiveModel::Errors:0x007f0d84604968 @base=#<BuildDetail id: nil, admin_sections_id: 8, admin_specs_id: 1, value: nil, created_at: nil, updated_at: nil, options: {"admin_stuffs"=>{"id"=>"3"}}>, @messages={:value=>["needs to be filled!"]}, @details={:value=>[{:error=>:blank}]}>
                }
            }
        },
        :"2" => {
            :section => {
                :"6" => {
                    :errors => #<ActiveModel::Errors:0x007f0d80234990 @base=#<BuildDetail id: nil, admin_sections_id: 6, admin_specs_id: 2, value: nil, created_at: nil, updated_at: nil, options: {}>, @messages={:value=>["needs to be filled!"]}, @details={:value=>[{:error=>:blank}]}>
                },
                :"7" => {
                    :errors => #<ActiveModel::Errors:0x007f0d8977dc68 @base=#<BuildDetail id: nil, admin_sections_id: 7, admin_specs_id: 2, value: nil, created_at: nil, updated_at: nil, options: {}>, @messages={:value=>["needs to be filled!"]}, @details={:value=>[{:error=>:blank}]}>
                },
                :"8" => {
                    :errors => #<ActiveModel::Errors:0x007f0d8416a0d8 @base=#<BuildDetail id: nil, admin_sections_id: 8, admin_specs_id: 2, value: nil, created_at: nil, updated_at: nil, options: {}>, @messages={:value=>["needs to be filled!"]}, @details={:value=>[{:error=>:blank}]}>
                }
            }
        }
    }
}

I can say which elements are belong to which [:spec]/[:section] but there is no documentation on how can I pass the :errors to the tag? i.e Is there anything like the following in the api?

<%= f.text_field :foobar, error: @errors[:spec][spec_id][:section][section_id][:errors] %>

Thanks in advance.

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