Search code examples
ruby-on-railsrubyrubymine

Why doesn't Rubymine recognize my namespaced inherited controller?


I have a namespace called backend and the following controller application_controller.rb:

class Backend::ApplicationController < ApplicationController
end

Now I inherit this controller from my user controller:

class Backend::UserController < Backend::ApplicationController
  def index
    @users = User.all
  end

  ...
end

For the inheritance of the application controller Rubymine shows me the following error:

Expected: ; or end of line

This code is fine for the ruby interpreter. How can I teach this to Rubymine?

I'm on RubyMine 2018.2.3 and using Ruby 2.5.1p57.

Thank you in advance!


Solution

  • I'm guessing that you should try the proper "longhand" way of actually opening the module.

    These two approaches are not actually equivalent:

    class Backend::ApplicationController < ApplicationController
    end
    
    module Backend
      class ApplicationController < ::ApplicationController
      end
    end
    

    As the later actually properly sets the module nesting to work as expected:

    module Backend
      # this class will inherit from Backend::ApplicationController
      # and not ::ApplicationController
      class UserController < ApplicationController
      end
    end
    

    In general the "short-cut" definition (class Foo::Bar) of "namespaced" classes should be avoided as it invites problems with constant lookup.