gregschmit/rails-rest-framework

View on GitHub
app/views/rest_framework/routes_and_forms/_raw_form.html.erb

Summary

Maintainability
Test Coverage
<div style="max-width: 60em; margin: auto">
  <div class="mb-2">
    <label class="form-label w-100">Route
      <select class="form-control form-control-sm" id="rawFormRoute">
        <% @_rrf_form_routes_raw.each do |route| %>
          <% path = @route_props[:with_path_args].call(route[:route]) %>
          <option
            value="<%= route[:verb] %>:<%= path %>"
            data-supports-files="<%= !route[:action].in?(["update_all", "destroy", "destroy_all"]) ? "true" : "" %>"
          ><%= route[:verb] %> <%= route[:relative_path] %></option>
        <% end %>
      </select>
    </label>
  </div>

  <div class="mb-2">
    <label class="form-label w-100">Media Type
      <select class="form-control form-control-sm" id="rawFormMediaType">
        <% ["application/json", "application/x-www-form-urlencoded", "multipart/form-data"].each do |t| %>
          <option value="<%= t %>"><%= t %></option>
        <% end %>
      </select>
    </label>
  </div>

  <div class="mb-2">
    <label class="form-label w-100">Content
      <textarea class="form-control form-control-sm" style="font-family: monospace" id="rawFormContent" rows="8" cols="60"></textarea>
    </label>
  </div>

  <% if @is_model_controller && model = controller.class.get_model %>
    <% if attachment_reflections = model.attachment_reflections.presence %>
      <div class="mb-2" style="display: none" id="rawFilesFormWrapper">
        <%= form_with(
          model: @record,
          url: "",
          id: "rawFilesForm",
          scope: "",
        ) do |form| %>
          <% attachment_reflections.each do |field, ref| %>
            <label class="form-label w-100"><%= controller.class.get_label(field) %>
              <%= form.file_field field, multiple: ref.macro == :has_many_attached %>
            </label>
          <% end %>
        <% end %>
      </div>
    <% end %>
  <% end %>

  <button type="button" class="btn btn-primary" style="float: right" onclick="rrfSubmitRawForm(this)">Submit</button>
</div>