From a670b740fae2f01209b29c6766ea4a5e2b6b059f Mon Sep 17 00:00:00 2001 From: CoralineAda Date: Wed, 30 Oct 2024 21:24:00 -0500 Subject: [PATCH] Show suggestions on new category page --- app/assets/stylesheets/styles.css | 2 +- app/controllers/categories_controller.rb | 3 +- app/jobs/category_suggestions_job.rb | 1 - app/views/categories/new.html.erb | 41 +++++++++++++++++------- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/assets/stylesheets/styles.css b/app/assets/stylesheets/styles.css index 7cc3f72..20732c6 100644 --- a/app/assets/stylesheets/styles.css +++ b/app/assets/stylesheets/styles.css @@ -76,7 +76,7 @@ ul, ol { list-style-position: inside; - margin: 1.5rem 0 1.5rem 1.5rem; + margin: 0 0 1.5rem 1.5rem; } em { diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 19aa7a8..e255b91 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -15,7 +15,8 @@ def show end def new - @category = Category.new(name: "New Category", context: @question.context.name) + @category = Category.new(name: "New Category", context: @question.context.name) + @context = @question.context end def create diff --git a/app/jobs/category_suggestions_job.rb b/app/jobs/category_suggestions_job.rb index cdbcc49..9a91e3b 100644 --- a/app/jobs/category_suggestions_job.rb +++ b/app/jobs/category_suggestions_job.rb @@ -8,7 +8,6 @@ class CategorySuggestionsJob def perform(context_id) Rails.logger.info("CategorySuggestionsJob running with context id #{context_id}") return unless context = Context.find(context_id) - sleep(2) context.suggest_categories context.update_attribute(:suggestions_updated_at, DateTime.now) end diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb index f2c8fb9..550568d 100644 --- a/app/views/categories/new.html.erb +++ b/app/views/categories/new.html.erb @@ -2,15 +2,32 @@

Add a Category

-<%= form_with model: @category, url: question_categories_path(question_id: @question.id) do |f| %> -
- <%= label :name, "Name" %> - <%= f.text_field :name %> -
-
- <%= label :description, "Description" %> - <%= f.text_area :description %> -
- <%= f.hidden_field :context %> - <%= f.submit "Create" %> -<% end %> +
+ +
+ <%= form_with model: @category, url: question_categories_path(question_id: @question.id) do |f| %> +
+ <%= label :name, "Name" %> + <%= f.text_field :name %> +
+
+ <%= label :description, "Description" %> + <%= f.text_area :description %> +
+ <%= f.hidden_field :context %> + <%= f.submit "Create" %> + <% end %> +
+ + <% if @context.suggested_categories.any? %> +
+

Suggested categories:

+
    + <% @context.suggested_categories.each do |suggestion| %> +
  • <%= suggestion %>
  • + <% end %> +
+
+ <% end %> + +