Getting the right HTML for Rails Nested Model Forms

Last week I had trouble getting Rails’s Nested Model Forms feature to work for me in exactly the way I wanted.  Two things were working against me: 1) No documentation that shows the complete process for nested models from ERB to HTML, to HTTP parameters, to controller code. and 2) Blogs and suggestions I came up with were close, but didn’t work.

Since I was using javascript rather than ERB to create the hidden input tags in the HTML, I needed to know exactly how to construct my tags to tell rails what to do with my nested models. (Read More)

dynamic has_many association (for lack of a better name)

Yesterday I had one of those moments in Rails where I knew there must be a really good way to do something, there had to be.  But all I could think of was the brute force way.

Technically speaking, I wanted to create collections of child objects on a parent object where the membership of each collection depended on whether the parent and the child shared an attribute in common.

In simpler terms, imagine you have a group blog.  Each post in the blog is written by one of several authors.  A Post belongs to an Author. (Read More)