I'd like to show or hide a few fields in a form in Rails, depending on the state of a select field in the form. I don't (currently) need a second database lookup for the fields, so I'm trying to keep it all confined to the view. I have the outline sketched out, but I'm having some trouble with the implementation details.
My initial thought was to use observe_field
and call Element.show etc. etc., but then I'd have to write a Javascript conditional. This will probably have to work, but I want to avoid it if I can.
Another approach would be to use observe_field
to request a RJS template, and replace_html
to insert the fields. Not bad, but since I'm using a form_for
block I'd either have to pass the form instance all the way through the RJS template to do it right.
I could also update the record on each pass, and display the form under the new conditions, but that's what I'm trying to avoid. It'd be so much simpler to just do this all in the view.
What am I missing here? What's the accepted practice for conditional show/hide forms in Rails?