Post History
#3: Post edited
- ## 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
- 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
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 ```