I weird errors. No really. I love having to dig into a system to discover why a certain function or method acts in a certain way.
Today I was doing Rails work and came upon a weird error, where I would load the image
I couldn’t quite see from the data, where I got that
h from, so the hunt began.
The code, which I had fiddled with was this
After having found the error, I can see that I did a hell of a job rewriting the above method.
Of course the
#map returns an array and my
return on the first line does not.
The reason I got
/images/h out was that we were using the
#photos method in
photos is the first method.
It checks if the array contains an element and then uses that first element to create the image tag.
However(!) in Rails we have a
String#first method, which just takes the first character out of the string
My image URLs were of course starting with
"http", so I kept getting
This is a weird problem to have in my mind. I simply love it.
When trying to figure out the problem, I launched an
rails console) and fired some commands at it.
I should of course have used the Rails console (but our Rails environment is sooo slow to boot):
Oh well. Lesson learned I guess.
I quickly fixed my err in the first snippet and changed the second to be nicer: