Project

General

Profile

Actions

Defect #18332

closed

Error when displaying a news with comments in reverse order

Added by Denis Savitskiy about 10 years ago. Updated about 10 years ago.

Status:
Closed
Priority:
High
Category:
News
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

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

Actions #1

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 )

Actions #2

Updated by Toshi MARUYAMA about 10 years ago

  • Target version set to 2.6.1
Actions #3

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

Actions #4

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.

Actions #5

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!

Actions #6

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.

Actions #7

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.

Actions

Also available in: Atom PDF