Skip to content

Commit

Permalink
Show suggestions on new category page
Browse files Browse the repository at this point in the history
  • Loading branch information
CoralineAda committed Oct 31, 2024
1 parent 80fad8c commit a670b74
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/jobs/category_suggestions_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 29 additions & 12 deletions app/views/categories/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,32 @@

<h1>Add a Category</h1>

<%= form_with model: @category, url: question_categories_path(question_id: @question.id) do |f| %>
<fieldset>
<%= label :name, "Name" %>
<%= f.text_field :name %>
</fieldset>
<fieldset>
<%= label :description, "Description" %>
<%= f.text_area :description %>
</fieldset>
<%= f.hidden_field :context %>
<%= f.submit "Create" %>
<% end %>
<div class="two-column">

<div class="column">
<%= form_with model: @category, url: question_categories_path(question_id: @question.id) do |f| %>
<fieldset>
<%= label :name, "Name" %>
<%= f.text_field :name %>
</fieldset>
<fieldset>
<%= label :description, "Description" %>
<%= f.text_area :description %>
</fieldset>
<%= f.hidden_field :context %>
<%= f.submit "Create" %>
<% end %>
</div>

<% if @context.suggested_categories.any? %>
<div class="column">
<h2>Suggested categories:</h2>
<ul>
<% @context.suggested_categories.each do |suggestion| %>
<li><%= suggestion %></li>
<% end %>
</ul>
</div>
<% end %>

</div>

0 comments on commit a670b74

Please sign in to comment.