Use datalist as a poor man's autocomplete for now
This commit is contained in:
@@ -11,7 +11,7 @@ class CategoriesController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@category = Category.new(category_params)
|
||||
@category = Category.find_or_create_by(category_params)
|
||||
@category.save
|
||||
|
||||
@category.splats << @splat
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
<turbo-frame id="new_catgory">
|
||||
<%= form_with model: [@splat, @category], data: { turbo_frame: "_top" } do |form| %>
|
||||
<%= form.text_field :title, class: "input borderless", autofocus: "on" %>
|
||||
<%= form.text_field :title, class: "input borderless", autofocus: "on", list: "categories-list" %>
|
||||
<%= form.submit "Create Category", hidden: true %>
|
||||
|
||||
<datalist id="categories-list">
|
||||
<%= Category.all.each do | category | %>
|
||||
<option value="<%= category.title %>"></option>
|
||||
<% end %>
|
||||
</datalist>
|
||||
<% end %>
|
||||
</turbo-frame>
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
<%= link_to splat, class: "splat__title-link flex align-center gap flex-item-grow" do %>
|
||||
<strong><%= splat.title %></strong>
|
||||
<% end %>
|
||||
<small class="flex align-center gap flex-item-shrink">
|
||||
<small class="flex align-center gap flex-item-no-shrink">
|
||||
<% splat.categories.each do |category| %>
|
||||
<%= link_to "# #{ category.title }", splats_path(category_id: category.id) %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user