-
|
Hello! I'm trying to create a component that would let me extract all the common logic i use in all my index views. For this specific examle, it's about having a table with results at the bottom and "quick filters" area above it. Every single index screen has such quick filters section but they differ by filters available in there and a design of the fields in general. That's how this component looks so far: And what i aim for is to be able to use a following code in order to "inject" quick filter inputs into my component: The above example will obviously raise an exception as Any tips highly welcome! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
There's probably a cleaner way to do this, but what I've got so far is:
<%= render FormComponent.new do |c| %>
<% c.form do |f| %>
<%= f.text_field :query %>
<% end %>
<% end %>If you're using |
Beta Was this translation helpful? Give feedback.
-
|
Very helpful! Here's what mine ended up as if anyone comes across it Component: and the component template The only added thing is the |
Beta Was this translation helpful? Give feedback.
There's probably a cleaner way to do this, but what I've got so far is:
renders_one :form, ->(&block) { form_with(**form_opts, &block) }.form_optscan be a method on the component that returns the hash of options you'd otherwise pass toform_with,fields, orfields_for. You can also change the lambda to accept params if you wish.If you're using
fieldsorfields_forrather thanform_with, you could probablydelegate_missing_tothose because they don't need to render a surrounding form tag, but I haven't …