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
#3: Post edited by user avatar trichoplax‭ · 2025-03-03T22:43:48Z (6 days ago)
Typo in code block
  • ## Hidden helper functions
  • There are additional helper functions defined that can be used from the view files. These can be found in a separate `helpers` directory. In this particular case, the `expandable?` function is defined on line 8 of the following file:
  • ```
  • app/helpers/categories_helper.rb
  • ```
  • ```ruby
  • def expandable?
  • (defined?(@category) && !@category&.id.nil? && !current_page?(new_category_url)) ||
  • (defined?(@post) && !@post&.category.nil?) ||
  • (defined?(@question) && !@question&.category.nil?) ||
  • (defined?(@article) && !@article&.category.nil?)
  • end
  • ```
  • ## Instance variables with @
  • A variable that starts with an "at" symbol, such as `@post`, is a class instance variable. It is accessible from anywhere inside an instance of the class. In the case of Rails, an instance variable that is defined in the controller is available in the view.
  • Note that without the leading `@` a variable is just local, not accessible from anywhere else. The variable `post` is not related to the instance variable `@post`.
  • In order for the `expandable?` function to return true, you could either define `@post` in the controller before it renders the view, or you could modify the `expandable?` function to also look for `@edit`. For example, you could add an extra condition at the end to give the following:
  • ```ruby
  • def expandable?
  • (defined?(@category) && !@category&.id.nil? && !current_page?(new_category_url)) ||
  • (defined?(@post) && !@post&.category.nil?) ||
  • (defined?(@question) && !@question&.category.nil?) ||
  • (defined?(@article) && !@article&.category.nil?) ||
  • (defined?(@edit) && !edit.post&.category&.nil?)
  • end
  • ```
  • This should cause `expandable?` to return true for a suggested edit page, but presumably the view will still be looking for `@post`, `@question`, or `@article` to find out what category to display, so you might need to make it also accept `@edit`.
  • ## Hidden helper functions
  • There are additional helper functions defined that can be used from the view files. These can be found in a separate `helpers` directory. In this particular case, the `expandable?` function is defined on line 8 of the following file:
  • ```
  • app/helpers/categories_helper.rb
  • ```
  • ```ruby
  • def expandable?
  • (defined?(@category) && !@category&.id.nil? && !current_page?(new_category_url)) ||
  • (defined?(@post) && !@post&.category.nil?) ||
  • (defined?(@question) && !@question&.category.nil?) ||
  • (defined?(@article) && !@article&.category.nil?)
  • end
  • ```
  • ## Instance variables with @
  • A variable that starts with an "at" symbol, such as `@post`, is a class instance variable. It is accessible from anywhere inside an instance of the class. In the case of Rails, an instance variable that is defined in the controller is available in the view.
  • Note that without the leading `@` a variable is just local, not accessible from anywhere else. The variable `post` is not related to the instance variable `@post`.
  • In order for the `expandable?` function to return true, you could either define `@post` in the controller before it renders the view, or you could modify the `expandable?` function to also look for `@edit`. For example, you could add an extra condition at the end to give the following:
  • ```ruby
  • def expandable?
  • (defined?(@category) && !@category&.id.nil? && !current_page?(new_category_url)) ||
  • (defined?(@post) && !@post&.category.nil?) ||
  • (defined?(@question) && !@question&.category.nil?) ||
  • (defined?(@article) && !@article&.category.nil?) ||
  • (defined?(@edit) && !@edit.post&.category&.nil?)
  • end
  • ```
  • This should cause `expandable?` to return true for a suggested edit page, but presumably the view will still be looking for `@post`, `@question`, or `@article` to find out what category to display, so you might need to make it also accept `@edit`.
#2: Post edited by user avatar trichoplax‭ · 2025-03-03T22:38:08Z (6 days ago)
Add explanation of instance variables for the next step
  • There are additional helper functions defined that can be used from the view files. These can be found in a separate `helpers` directory. In this particular case, the `expandable?` function is defined on line 8 of the following file:
  • ```
  • app/helpers/categories_helper.rb
  • ```
  • ```ruby
  • def expandable?
  • (defined?(@category) && !@category&.id.nil? && !current_page?(new_category_url)) ||
  • (defined?(@post) && !@post&.category.nil?) ||
  • (defined?(@question) && !@question&.category.nil?) ||
  • (defined?(@article) && !@article&.category.nil?)
  • end
  • ```
  • ## Hidden helper functions
  • There are additional helper functions defined that can be used from the view files. These can be found in a separate `helpers` directory. In this particular case, the `expandable?` function is defined on line 8 of the following file:
  • ```
  • app/helpers/categories_helper.rb
  • ```
  • ```ruby
  • def expandable?
  • (defined?(@category) && !@category&.id.nil? && !current_page?(new_category_url)) ||
  • (defined?(@post) && !@post&.category.nil?) ||
  • (defined?(@question) && !@question&.category.nil?) ||
  • (defined?(@article) && !@article&.category.nil?)
  • end
  • ```
  • ## Instance variables with @
  • A variable that starts with an "at" symbol, such as `@post`, is a class instance variable. It is accessible from anywhere inside an instance of the class. In the case of Rails, an instance variable that is defined in the controller is available in the view.
  • Note that without the leading `@` a variable is just local, not accessible from anywhere else. The variable `post` is not related to the instance variable `@post`.
  • In order for the `expandable?` function to return true, you could either define `@post` in the controller before it renders the view, or you could modify the `expandable?` function to also look for `@edit`. For example, you could add an extra condition at the end to give the following:
  • ```ruby
  • def expandable?
  • (defined?(@category) && !@category&.id.nil? && !current_page?(new_category_url)) ||
  • (defined?(@post) && !@post&.category.nil?) ||
  • (defined?(@question) && !@question&.category.nil?) ||
  • (defined?(@article) && !@article&.category.nil?) ||
  • (defined?(@edit) && !edit.post&.category&.nil?)
  • end
  • ```
  • This should cause `expandable?` to return true for a suggested edit page, but presumably the view will still be looking for `@post`, `@question`, or `@article` to find out what category to display, so you might need to make it also accept `@edit`.
#1: Initial revision by user avatar trichoplax‭ · 2025-03-03T20:53:10Z (6 days ago)
There are additional helper functions defined that can be used from the view files. These can be found in a separate `helpers` directory. In this particular case, the `expandable?` function is defined on line 8 of the following file:

```
app/helpers/categories_helper.rb
```

```ruby
  def expandable?
    (defined?(@category) && !@category&.id.nil? && !current_page?(new_category_url)) ||
      (defined?(@post) && !@post&.category.nil?) ||
      (defined?(@question) && !@question&.category.nil?) ||
      (defined?(@article) && !@article&.category.nil?)
  end
```