Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

60%
+1 −0
Q&A How does a view know it should show the category bar?

1 answer  ·  posted 6d ago by Monica Cellio‭  ·  last activity 6d ago by trichoplax‭

#2: Post edited by user avatar Monica Cellio‭ · 2025-03-03T22:07:14Z (6 days ago)
  • Pages that are "in" a category show the category bar at the top, like this:
  • ![suggested edits page with Q&A: posts, tags, edits](https://collab.codidact.org/uploads/fhu16bw00j7xfyy491pojaxefy77)
  • An individual suggested edit should logically be "in" a category too, but isn't shown that way:
  • ![category bar is missing](https://collab.codidact.org/uploads/nlmwjgz4ul8l30jssbccs6b7161y)
  • I'm trying to figure out how that bar gets added to pages, so I can [fix this](https://github.com/codidact/qpixel/issues/1408), but I'm having trouble understanding the view code.
  • It's apparently not in the individual page views themselves. For example, the view for that first screenshot, `app/views/suggested_edit/category_index.html.erb`, begins with the `<h1>` for the title. I looked at a couple more, like `app/views/tags/show.html.erb` and `app/views/posts/show.html.erb`, and found the same thing (modulo some HTML header meta stuff that I don't understand but seems unrelated).
  • I see that `app/views/layouts` exists, so I looked around in there. `_header.html.erb` contains the actual category bar, with the category name and links for posts, tags, and edits. `application.html.erb` renders it. Taking a closer look at `_header.html.erb`, I see some checks around this code block:
  • ```
  • <% if expandable? %>
  • <div class="container category-header--container">
  • <!-- ... -->
  • <div class="category-header--name">
  • <%= current_cat.name %>
  • </div>
  • <div class="category-header--nav">
  • <!-- ... link to Posts, link to Tags -->
  • <%= link_to suggested_edits_queue_path(current_cat),
  • class: "category-header--nav-item #{active?(current_cat) && controller_name == 'suggested_edit' ? 'is-active' : ''}" do %>
  • Edits
  • <% if pending_suggestions? && check_your_privilege('edit_posts') %>
  • <span class="badge is-status" title="Suggested edits pending"></span>
  • <% end %>
  • <% end %>
  • <!-- ... -->
  • ```
  • This `expandable` check seems to be the key to getting this bar to show up, but that's where I got stuck. How do other pages (posts, category, tags, the actual list of edits) get set to "expandable"? It's not being set in their views. I looked around in the controllers and didn't find it there, and it's not a database column (didn't expect it to be, but checked anyway). Or is `expandable` a red herring, and I need to be looking for something else in all these views?
  • Pages that are "in" a category show the category bar at the top, like this:
  • ![suggested edits page with Q&A: posts, tags, edits](https://collab.codidact.org/uploads/fhu16bw00j7xfyy491pojaxefy77)
  • An individual suggested edit should logically be "in" a category too, but isn't shown that way:
  • ![category bar is missing](https://collab.codidact.org/uploads/nlmwjgz4ul8l30jssbccs6b7161y)
  • I'm trying to figure out how that bar gets added to pages, so I can [fix this](https://github.com/codidact/qpixel/issues/1408), but I'm having trouble understanding the view code.
  • It's apparently not in the individual page views themselves. For example, the view for that first screenshot, `app/views/suggested_edit/category_index.html.erb`, begins with the `<h1>` for the title. I looked at a couple more, like `app/views/tags/show.html.erb` and `app/views/posts/show.html.erb`, and found the same thing (modulo some HTML header meta stuff that I don't understand but seems unrelated).
  • I see that `app/views/layouts` exists, so I looked around in there. `_header.html.erb` contains the actual category bar, with the category name and links for posts, tags, and edits. `application.html.erb` renders it. Taking a closer look at `_header.html.erb`, I see some checks around this code block:
  • ```
  • <% if expandable? %>
  • <div class="container category-header--container">
  • <!-- ... -->
  • <div class="category-header--name">
  • <%= current_cat.name %>
  • </div>
  • <div class="category-header--nav">
  • <!-- ... link to Posts, link to Tags -->
  • <%= link_to suggested_edits_queue_path(current_cat),
  • class: "category-header--nav-item #{active?(current_cat) && controller_name == 'suggested_edit' ? 'is-active' : ''}" do %>
  • Edits
  • <% if pending_suggestions? && check_your_privilege('edit_posts') %>
  • <span class="badge is-status" title="Suggested edits pending"></span>
  • <% end %>
  • <% end %>
  • <!-- ... -->
  • ```
  • This `expandable` check seems to be the key to getting this bar to show up, but that's where I got stuck. How do other pages (posts, category, tags, the actual list of edits) get set to "expandable"? It's not being set in their views. I looked around in the controllers and didn't find it there, and it's not a database column (didn't expect it to be, but checked anyway). Or is `expandable` a red herring, and I need to be looking for something else in all these views?
  • --
  • [An answer](https://collab.codidact.org/posts/293511/293512#answer-293512) helpfully points out where `expandable?` is defined (and shows the code), but now I'm even more confused. That function returns true if `post` is defined and its category is not `nil`. The view for an individual suggested edit already contains:
  • ```
  • <% post = @edit.post %>
  • ```
  • To which I added (this should be redundant):
  • ```
  • <% category = @edit.post.category %>
  • ```
  • The post is properly formed and has a category. (You can see this if you click through to the post from the suggested edit.) So why isn't the category header showing up, either already or with my added definition of `category`?
#1: Initial revision by user avatar Monica Cellio‭ · 2025-03-03T18:58:57Z (6 days ago)
How does a view know it should show the category bar?
Pages that are "in" a category show the category bar at the top, like this:

![suggested edits page with Q&A: posts, tags, edits](https://collab.codidact.org/uploads/fhu16bw00j7xfyy491pojaxefy77)

An individual suggested edit should logically be "in" a category too, but isn't shown that way:

![category bar is missing](https://collab.codidact.org/uploads/nlmwjgz4ul8l30jssbccs6b7161y)

I'm trying to figure out how that bar gets added to pages, so I can [fix this](https://github.com/codidact/qpixel/issues/1408), but I'm having trouble understanding the view code.

It's apparently not in the individual page views themselves.  For example, the view for that first screenshot, `app/views/suggested_edit/category_index.html.erb`, begins with the `<h1>` for the title.  I looked at a couple more, like `app/views/tags/show.html.erb` and `app/views/posts/show.html.erb`, and found the same thing (modulo some HTML header meta stuff that I don't understand but seems unrelated).

I see that `app/views/layouts` exists, so I looked around in there.  `_header.html.erb` contains the actual category bar, with the category name and links for posts, tags, and edits. `application.html.erb` renders it.  Taking a closer look at `_header.html.erb`, I see some checks around this code block:

```
    <% if expandable? %>
      <div class="container category-header--container">
      <!-- ... -->
        <div class="category-header--name">
          <%= current_cat.name %>
        </div>
        <div class="category-header--nav">
          <!-- ... link to Posts, link to Tags -->
          <%= link_to suggested_edits_queue_path(current_cat),
                      class: "category-header--nav-item #{active?(current_cat) && controller_name == 'suggested_edit' ? 'is-active' : ''}" do %>
            Edits
            <% if pending_suggestions?  && check_your_privilege('edit_posts') %>
              <span class="badge is-status" title="Suggested edits pending"></span>
            <% end %>
          <% end %>
  <!-- ... -->
```

This `expandable` check seems to be the key to getting this bar to show up, but that's where I got stuck.  How do other pages (posts, category, tags, the actual list of edits) get set to "expandable"?  It's not being set in their views.  I looked around in the controllers and didn't find it there, and it's not a database column (didn't expect it to be, but checked anyway).  Or is `expandable` a red herring, and I need to be looking for something else in all these views?