Defect #18332
closedError when displaying a news with comments in reverse order
0%
Description
Extra bang after
@comments.reverse
in news_controller.rb causes 500 error if no comments are present while
User.current.wants_comments_in_reverse_order? == true
Updated by Denis Savitskiy about 10 years ago
Well, the solution is as simple as this: remove '!' after 'reverse' (link: source:/trunk/app/controllers/news_controller.rb#L62 )
Updated by Jean-Philippe Lang about 10 years ago
- Status changed from New to Needs feedback
- Target version deleted (
2.6.1)
Please read SubmittingBugs.
@comments can not be nil in NewsController#show. Also, #reverse! is required here, not #reverse:
http://www.ruby-doc.org/core-2.1.5/Array.html#method-i-reverse
Updated by Denis Savitskiy about 10 years ago
Jean-Philippe Lang wrote:
Please read SubmittingBugs.
@comments can not be nil in NewsController#show. Also, #reverse! is required here, not #reverse:
http://www.ruby-doc.org/core-2.1.5/Array.html#method-i-reverse
What is the purpose of this bang? You are not storing the order. You simply change the order in array before showing it to user.
Updated by Jean-Philippe Lang about 10 years ago
- Subject changed from Extra bang after @comments.reverse in news_controller causes 500 error to Error when displaying a news with comments in reverse order
- Status changed from Needs feedback to Resolved
- Assignee set to Jean-Philippe Lang
- Target version set to 2.6.1
- Resolution set to Fixed
Fixed in r13595.
The problem was not with the bang nor the fact that there are no comments. It would have been easier to get it with your stack trace but thanks anyway for reporting this.
What is the purpose of this bang? You are not storing the order. You simply change the order in array before showing it to user.
#reverse
returns a reversed array but leaves the array unchanged, so we'd have to use @comments = @comments.reverse
instead of @comments.reverse!
Updated by Jean-Philippe Lang about 10 years ago
- Status changed from Resolved to Closed
- Target version deleted (
2.6.1) - Affected version deleted (
2.6.0)
2.6 stable is not affected, trunk only.
Updated by Denis Savitskiy about 10 years ago
Jean-Philippe Lang wrote:
Fixed in r13595.
Thanks!
#reverse
returns a reversed array but leaves the array unchanged, so we'd have to use@comments = @comments.reverse
instead of@comments.reverse!
Sure! I didn't mention that.