unabridged / motion

Reactive frontend UI components for Rails in pure Ruby
https://github.com/unabridged/motion
MIT License
697 stars 19 forks source link

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

Closed revickulous2001 closed 4 years ago

revickulous2001 commented 4 years ago

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?

alecdotninja commented 4 years ago

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.