I ran into this problem recently. It was pretty hard to correlate the error to the solution.
hitting my /users/new method had suddenly produced this error
undefined method `model_name' for NilClass:Class
in my view on this line
<%= form_for(@user) do |f| %>
The obvious thought was that somehow my controller did not define @user – but it did. I put a debug statement in the new controller which did not execute.
The real reason for the error? A syntax error elsewhere in the file. There was an unbalanced ‘end’ statement in a different method in the users controller. I would’ve expected a syntax error, but no such luck. Fixing this resolved the problem