unabridged/motion

It doesn't seem that Motion supports passing in a form builder object.

revickulous2001 opened this issue · 1 comments

I was trying to pass a form builder object into a ViewComponent that is using motion. Doing something like:

<%= form_with model: my_model, local: true do |form| %>
  <%= 
     render MyComponent.new(
       data: @data,
       form_object: form
     ) 
   %>
<% end %>

Is throwing Motion::UnrepresentableStateError.

This seems to be because Motion is trying to Marshal.dump the component state and that is conflicting with the form builder object.

If I can't pass the form builder object in this way, how would I be able to use Motion to render some code within the component such as: <%= form_object.fields_for :association %>? Is there a workaround to this or am I simply doing something wrong?

I suspect the issue here is that the form builder contains a reference to the view context. We can probably get around this by providing custom _marshal_dump and _marshal_load implementations for this object.

In the meantime, a simple workaround would be to move the form_with into the component and pass in the model instead.