From a79b27020add4855b0920c653fc3fc803b66e30b Mon Sep 17 00:00:00 2001 From: Runar Ingebrigtsen Date: Fri, 23 Jan 2026 22:10:51 +0100 Subject: [PATCH] edit category --- app/controllers/entries_controller.rb | 17 ++++++- app/views/entries/edit.html.erb | 70 +++++++++++++++++++++++++++ app/views/entries/show.html.erb | 1 + 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 app/views/entries/edit.html.erb diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb index 53ca006..dab8f8a 100644 --- a/app/controllers/entries_controller.rb +++ b/app/controllers/entries_controller.rb @@ -1,5 +1,5 @@ class EntriesController < ApplicationController - before_action :set_entry, only: [ :show ] + before_action :set_entry, only: [ :show, :edit, :update ] def index @language_code = params[:language].presence @@ -49,6 +49,17 @@ class EntriesController < ApplicationController def show end + def edit + end + + def update + if @entry.update(entry_params) + redirect_to entry_path(@entry), notice: "Entry updated." + else + render :edit, status: :unprocessable_entity + end + end + def download @entries = Entry.order(:id) respond_to do |format| @@ -64,4 +75,8 @@ class EntriesController < ApplicationController def set_entry @entry = Entry.find(params[:id]) end + + def entry_params + params.require(:entry).permit(:category) + end end diff --git a/app/views/entries/edit.html.erb b/app/views/entries/edit.html.erb new file mode 100644 index 0000000..d8495df --- /dev/null +++ b/app/views/entries/edit.html.erb @@ -0,0 +1,70 @@ +<% content_for :title, "Edit Entry" %> + + + +
+
+ <%= link_to "← Back to entry", entry_path(@entry), class: "text-sm text-slate-500 hover:text-indigo-600" %> + <%= link_to "Back to search", entries_path, class: "text-sm text-slate-500 hover:text-indigo-600" %> +
+ +
+
+ Edit Category + <% if @entry.verified? %> +
+ + Verified +
+ <% else %> + Unverified + <% end %> +
+ +
+ <%= form_with model: @entry, class: "space-y-4" do |form| %> +
+ <%= form.label :category, "Category", class: "block text-xs font-bold text-slate-500 uppercase tracking-widest mb-2" %> + <%= form.select :category, + Entry.categories.keys.map { |key| [key.tr("_", " ").capitalize, key] }, + {}, + class: "block w-full border-slate-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" %> +
+
+ <%= form.submit "Save Category", class: "bg-indigo-600 text-white px-4 py-2 rounded-lg text-sm font-semibold hover:bg-indigo-700 transition" %> +
+ <% end %> + +
+ <% supported_languages.each do |language| %> + <% translation = entry_translation_for(@entry, language.code) %> + <% next if translation.blank? %> +
+
+ <%= "#{language.name} (#{language.code.upcase})" %> +
+

<%= translation %>

+
+ <% end %> +
+ + <% if @entry.notes.present? %> +
+

Context & Notes

+

<%= @entry.notes %>

+
+ <% end %> +
+
+
diff --git a/app/views/entries/show.html.erb b/app/views/entries/show.html.erb index b01f80d..c3a6216 100644 --- a/app/views/entries/show.html.erb +++ b/app/views/entries/show.html.erb @@ -21,6 +21,7 @@
<%= format_entry_category(@entry) %> + <%= link_to "Edit", edit_entry_path(@entry) if admin? %> <% if @entry.verified? %>