0

I've got a function in my rails controller (I know, not the rails way, but I find it easier to write in the controller when I have something big like this and then move to the model).

I have an error in a array that I'm looping through, unfortunately, the error is being added somewhere in the loop. It is a big array with lots of properties, and I'm trying to figure out where the error is being caused.

I think I can isolate which object in the array is causing the error, but I can't get it to print.

Aparently ruby has an

abort('message')
function, but that returns an error in rails.

return render isn't working, it gives me an error that render and/or redirect is being called multiple times. How can I do a php type die in this situation?

pedalpete
  • 21,076
  • 45
  • 128
  • 239

1 Answers1

1

This SO Post makes an excellent suggestion.

raise RuntimeError, 'Message goes here'

In the 'Message goes here' section you could even add in the array element:

array.each do |array_element|
     <logic>
     raise RuntimeError, "#{array_element.inspect}; Message goes here"
end
Community
  • 1
  • 1
ScottJShea
  • 7,041
  • 11
  • 44
  • 67