Rails 4 + Devise – User.find_by problems-Collection of common programming errors

This code:

def getUser(email_address)
    User.find_by :email email_address
end

throws a syntax error:

requests_controller.rb:24: syntax error, unexpected tIDENTIFIER, expecting keyword_end

where this code (implemented in the exact same place/function without changing anything else) works:

def getUser(email_address)
    users = User.all
    found_user = nil
    users.each  do |user|
        if user.email == email_address
            found_user = user
            break
        end
    end
    found_user
end

Clearly the second implementation is horrible. With larger numbers of users its going to slow and stop. But I cannot see why the first one – which should be the right way to do it – will not even compile.

The syntax error message occurs when the class is loaded, before even the method is called. There is no issue with unbalanced “if” / “end” because the only lines changed are the ones shown.

I cannot understand why. I have tried lots of variations on this but none of them work.

As far as I can tell there should be no need to post more of my code, but if really someone wants me to I will. Note that this is not inside a devise controller, its just one of my other app controllers. But, User.all works, so why does User.find_by not even compile?

This page from the ActiveRecord docs suggests it should work. Loads of tutorials and help pages such as this one suggests that exact syntax. Devise must be doing something very surprising to the ActiveRecord api to break things this comprehensively.

Anyone know what is going on?