Return inside an method just returns and break that method and nothing else. Se code below.
def foo
return "foo"
return "bar"
end
puts my_method # this will puts "foo" and the second return will never be called.
However, in ruby you still can execute code after an return with ensure
.
def bar
return "bar"
ensure
@bar = 'Hello world'
end
puts bar # returns and prints "bar"
puts @bar # prints "Hello world" because the ensure part was still executed
And keep in mind that the last executed code in your method will be returned, so you don't always need to write return
before your value. And if you have an ensure part in your method the last executed code before that will be returned if you haven't returned something already.
And theres no need to return false in your before filters. If i remember right rails before version 3.1 did stop the controller when an before filter was returning an falsy value. Nil is still falsy in ruby and to strip some rows you cud write your filter like below because if no user is found @user
will be nil in this example.
def get_user
@user = User.find_by id: params[:id] # I use find_by to prevent exception, else we may return an 500 error which you may or may not want.
redirect_back unless @user
end