And return at the end of the method

Sometimes I see this code:

def bar
  #......
  if response && response.body
    #......
    render(:text => html) and return
  end
end

I wonder if it makes sense to use and returnat the very end of the method?

+4
source share
3 answers

I saw such code just not at the bottom of the method (this makes sense because the render is not the end of the method). But here I do not see the point.

See Avoid Double Render Mistakes .

+2
source

This will help to avoid double render errors. Layouts and rendering

+5
source

, render, render , : Render and/or redirect were called multiple times in this action

, - , , :

def bar
  ...
  x = true
  ...
  if x
   render(:text => html)
  end

  ...
  render(:text => html)
end
0

Source: https://habr.com/ru/post/1527503/


All Articles