I'm working on a Rails app where user can "design" forms. See the image below:
For this I have the following models:
class ProgramPart < ApplicationRecord
has_many :block_elements, dependent: :destroy
class BlockElement < ApplicationRecord
belongs_to :program_part
enum element_types: {
rich_content: 0,
textfield: 1,
textarea: 2
}
has_rich_text :content
I'm not quite sure how to present the dynamic form to the user and what approach to use.
Currently having:
<%= form_with [how should my form look when inputs are dynamic?] %>
<% @program_part.block_elements.each do |block| %>
<% if block.element_type == BlockElement.element_types[:rich_content] %>
<%= block.content %>
<% elsif block.element_type == BlockElement.element_types[:textfield] %>
<%= block.question %>
<!-- not sure how this should look -->
<%= @form_builder.text_field(:answer_value)%>
<% elsif block.element_type == BlockElement.element_types[:textarea] %>
<!-- textarea -->
<% end %>
<% end %>
<% end %>
Have anyone implemented something similar or knows any good resource for it?

block.element_type == BlockElement.element_types[:rich_content]which is very long and ugly just use the inquisition methods provided by the enum macro.if block.rich_content?.