Ruby :: Sometimes on Rails

The humane programming language. Be nice. Have fun. Lurkers...
May 16, 2017 02:22
Oh, god, I just saw the best bad SO question ever. It doesn't deserve any upvotes (quite the opposite), but I had to say something, somewhere. stackoverflow.com/questions/43991426/…
 
Oct 27, 2016 01:01
Posted the answer
Oct 27, 2016 00:53
Sure, no problem
Oct 27, 2016 00:52
Check your ApplicationController, as well as any concerns. Or just grep the source for rescue_from
Oct 27, 2016 00:52
Oh, rescue_from is available in rails 4, google just pulled up the rails 5 docs by default
Oct 27, 2016 00:51
I would bet if you just stick a raise 'oops' line in one of those methods, you'll get the same behavior
Oct 27, 2016 00:51
It's where you specify what to do if there's an exception during controller code
Oct 27, 2016 00:50
No, not a gem, it's part of rails
Oct 27, 2016 00:50
using rescue_from, mostly?
Oct 27, 2016 00:50
Do you have any sort of global error handler installed?
Oct 27, 2016 00:49
Oh, wait.
Oct 27, 2016 00:48
Eh, ok. Probably not gonna cause a redirect, but, it should honestly have caused a NoMethodError, unless Result also defines the cvss_score method
Oct 27, 2016 00:46
I don't see how that would cause a redirect, but, I don't know how issue_severity is defined
Oct 27, 2016 00:45
Because above you have issue = result.issue, but bellow you just have issue = result
Oct 27, 2016 00:45
Oh, here's a thing: in the @minor_issues loop in the view, you're passing a Result object to the 'issue_severity` method, whereas above, in the major issues loop, you're passing an Issue object
Oct 27, 2016 00:43
Ok, just checking. Anyway, the only other thing I can think that would be pertinent is, what's inside layouts/_back_button.html.erb? Nothing I've seen so far really suggests what the problem might be.
Oct 27, 2016 00:43
What exactly do you think issues = results.select{ |issue| issue.issue_id} does? Because all it does is return all elements of results for which issue_id is not nil. Is that what it's supposed to do?
Oct 27, 2016 00:43
Also, on the previous line, .collect {|issue| issue} does basically nothing.
Oct 27, 2016 00:43
The last line of get_host_issues is a syntactical error: issues = results.select{ |issue| issue.issue_id, at the very least you need a closing } character, but you probably want something more.
 

 Helping West Coast Charlie

Helping West Coast Charlie
Oct 15, 2016 03:24
The <=> operator would have been useful if you wanted it to always come out sorted biggest-to-smallest no matter how it went in (or smallest to biggest, or any other proper sorting).
Oct 15, 2016 03:23
Anyway, @WestCoastCharlie, if you're reading this, I know you can't respond, but, from the comments you left clarifying how your method should work for non-sorted arrays, @roychri's answer is good.
Oct 15, 2016 03:22
Heh. So much for StackOverflow's chat system :-p
Oct 15, 2016 03:19
I didn't think comment upvotes gave rep?
Oct 15, 2016 03:18
I upvoted the question, if you do as well he can chat. We can remove the upvote later if that seems necessary (it always seemed weird to me that there's any threshold at all for this feature, though I guess it helps with spam?)
Oct 15, 2016 03:17
It's only 15
Oct 15, 2016 03:16
Do you remember what the rep threshold is?
Oct 15, 2016 03:16
Ah, whoops, he can't join chat without more rep
Oct 15, 2016 03:13
Ah, hello there WCC
Oct 15, 2016 03:12
It actually took me a minute; usually chat links in comments go straight to the room, not the room metadata page, don't they?
Oct 15, 2016 03:06
:-p
Oct 15, 2016 03:05
Yeah, you are almost certainly correct
Oct 15, 2016 03:05
Hey Roychri