Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #11379: Made the subtopics method #11380

Closed
wants to merge 12 commits into from
6 changes: 6 additions & 0 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -568,4 +568,10 @@ def fetch_counts
end

def topic_tree; end

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at class body end.

def subtopics
nodes = Tag.find_by(name: "parent:#{params[:topic]}") # here, we look for this special tag marking a node as having a parent
.nodes
.collect(&:slug) # collect the "slugs" i.e. the unique part of the URL, which should correspond to a tagname
render "tags/subtopic", layout: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so here, i think we also have to actually make the partial template, at: /app/views/tags/_subtopics.html.erb, and for now it can just print out the subtopics. If you'd like, you can look at the HTML you made in #11230 and use that?

Copy link
Contributor Author

@KarishmaVanwari KarishmaVanwari Sep 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jywarren :
I created the file _subtopics.html.erb with the following code so as to only print the subtopics when pointed at a URL say http://localhost:3000/tags/subtopic/one or http://localhost:3000/tags/subtopic/two:

<% @subtopics.each do |subtopic| %>
    <h1><%= subtopic %></h1>
<% end %>

However, it gives an error -

image

Is it because the tags "one" or "two" do not have any specified subtopics as such? But it doesn't seem so, since I just tried adding a check to see if @subtopics is nil. Let me know your thoughts on this!

Thanks!

end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
post 'comment/react/update/:id' => 'comment#react_update'

get 'topic-tree' => 'tag#topic_tree'
get 'tags/subtopic/:topic' => 'tag#subtopics'

# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
Expand Down
9 changes: 9 additions & 0 deletions test/functional/tag_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,15 @@ def setup
assert_not_nil assigns(:notes)
assert (notes & expected).present?
end

test 'subtopics partial' do
get :subtopics,
params: {
topic: 'test'
}
assert :success
assert_not_nil assigns(:subtopics)
end

test 'shows suggested tags' do
get :suggested, params: { id: 'spectr' }
Expand Down