Post History
#2: Post edited
- Pages that are "in" a category show the category bar at the top, like this:
- 
- An individual suggested edit should logically be "in" a category too, but isn't shown that way:
- 
- 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:
- 
- An individual suggested edit should logically be "in" a category too, but isn't shown that way:
- 
- 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
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:  An individual suggested edit should logically be "in" a category too, but isn't shown that way:  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?