NoRedInk / elm-rails / Rails.Decode

Types


type alias ErrorList field =
List ( field, String )

ErrorList is a type alias for a list of ( fields, String ) pairs, where field is a type we can use to reference which fields had errors.

type Field
    = Name
    | Password

decode : ErrorList Field

Decoding

errors : Dict String field -> Json.Decode.Decoder (ErrorList field)

Decodes errors passed from rails formatted like this:

{ errors: {errorName: ["Error String"] } }.

This function takes a Dict that is a map of all the fields you need decoded. It should look like this:

Dict.fromList
    [ ( "school", School )
    , ( "school.name", SchoolName )
    , ( "school.address", SchoolAddress )
    , ( "school.city", City )
    , ( "school.state", State )
    , ( "school.zip", Zip )
    , ( "school.country", Country )
    ]