Skip to content
Shop

CommunityJoin Our PatreonDonate

Sponsored Ads

Sponsored Ads

Forms

Input Field

erb
<div class="my-5">
  <%= form.label :count %>
  <%= form.number_field :count, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
</div>

Select Tag

erb
<%= form.label :supplier_id %>
<%= select_tag(:supplier_id,  
  options_from_collection_for_select(Supplier.all, :id, :name)) %>

Form Select

erb
<%= form.select :supplier_id,
  options_from_collection_for_select(
  Supplier.all,
  :id,
  :name
  ),
  {}
%>

Checkbox

erb
<div class="my-5">
  <%= form.label :available %>
  <%= form.check_box :available, class: "block mt-2 h-5 w-5" %>
</div>

Submit Button

erb
<div class="inline">
  <%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
</div>

form with

partial shared by new.html.erb and edit.html.erb

Code
erb
<%= form_with(model: product, local: true) do |form| %>
  <% if product.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(product.errors.count, "error") %> prohibited this product from being saved:</h2>

      <ul>
        <% product.errors.full_messages.each do |message| %>
          <li><%= message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :name %>
    <%= form.text_field :name %>
  </div>

  <div class="field">
    <%= form.label :sku %>
    <%= form.text_field :sku %>
  </div>

  <div class="field">
    <%= form.label :count %>
    <%= form.number_field :count %>
  </div>

  <div class="field">
    <%= form.label :description %>
    <%= form.text_area :description %>
  </div>

  <div class="field">
    <%= form.label :supplier %>
    <%= form.text_field :supplier %>
  </div>

  <div class="field">
    <%= form.label :popularity %>
    <%= form.number_field :popularity %>
  </div>

  <div class="field">
    <%= form.label :price %>
    <%= form.number_field :price %>
  </div>

  <div class="field">
    <%= form.label :available %>
    <%= form.check_box :available %>
  </div>

  <div class="field">
    <%= form.label :availableSince %>
    <%= form.date_field :availableSince %>
  </div>

  <div class="field">
    <%= form.label :image %>
    <%= form.file_field :image %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>