Blogmark

Instantiate a custom Rails FormBuilder without using form_with

via jbranchaud@gmail.com

https://justin.searls.co/posts/instantiate-a-custom-rails-formbuilder-without-using-form_with/
Ruby on Rails Justin Searls

I was working with a partial that I wanted to stream to the page with Hotwire. This partial was rendering a form element that would be streamed inline to a form already on the page. The form input helper needs a Rails FormBuilder object in order to be instantiated properly. In the Rails controller where I'm streaming the partial as the response, I don't have access to the relevant form object. So, the rendering errors.

Then I found this article from Justin Searls describing a FauxFormObject which can help get around this issue. I made it available as a helper, referenced the instance in the partial, made sure the form element name followed convention, and then all was working.