Good morning folks. In a model of mine, I created a method for displaying a row. The page wasn't working cause next and reify methods we're undefined , so I put a try on them. But the page doesn't load and is displaying this error on browser. "504 Gateway Time-out"
v = self.versions.first
if v.present?
while v.try(:reify).try(:reason).try(:name).blank? do
v = v.try(:next)
end
v.reify.try(:reason).try(:name)
end
What do you recommend me to make this code much cleaner and to prevent it for long page loading again ?
Your code is effectively same as below after first iteration of loop, which is a infinite loop
Your web server gives up while waiting for loop to terminate and hence reports -
504 - Gateway timeout
to user/browser.try
allows you to invoke a method on anil
objects without throwing any exception - if object wasnil
or if method was not implemented, it will returnnil
.So, lets say
v
was some object that did not implementreify
method, then,v.try(:reify)
will benil
Only solution for your problem is to ensure that your loop terminates.