-
Notifications
You must be signed in to change notification settings - Fork 184
Simpler FormBuilder
The idea is to fork/wrap simple_form or rewrite Rails' FormBuilder
, adopt all the goodness for a quick form rendering implementation, and remove all the ugliness.
collection :songs do
property :title
end
When rendering this with #fields_for
, we get a weird over-complicated form that results in an incoming hash. The form builder tries to prefix each collection item with an id, and so on.
{
album: {
songs: {
1234 => {title: "I Don't Know"},
5678 => {title: "Meant To Be"}
}
}
}
This hash has nothing to do with its representation in a JSON document. Why do forms and JSON API hashes differ in Rails? It doesn't make sense and overcomplicates the task of processing those.
What we really want is a simple array that gets processed by Reform "the natural way". Also, the prefixing doesn't help. When POSTing to /albums/1
, I already know that I'm posting to an album, so why would I use that stupid prefix?
This would be processable by Reform and representable without any hacks, and also represents the natural way you'd encode this data structure in JSON.
songs: [
{title: "I Don't Know"},
{title: "Meant To Be"}
]
{
album_attributes: {
}
}
The _attributes
suffix is an ugly hack from Rails, we don't need it in Reform. Again, this leads to a diverging JSON and form representation.
release_date(1i)
This should be a hash like
release_date: {"1i": ..}