Is it possible to define global variables for autocomplete? Let me explain what I mean:
current_user is used magically everywhere. This is almost generally an User model.
Is it possible to define this variable as User globally across workspace? So when i type current_user. it will auto-complete user model always and everywhere
I have definitions.rb on root which is based on your Rails tweaks from another issue.
You have a few different options. If you want it to be truly global, you could use the @!method directive on Kernel:
# @!method current_user
# @return [User]
module Kernel; end
But you could also apply it to specific classes or modules:
# @!method current_user
# @return [User]
class ApplicationController < ActionController::Base
# ...
end
The second option makes current_user visible in all of your controllers (i.e., any subclass of ApplicationController).
Depending on your app's architecture, there might be some other module where you could apply the directive for better accuracy.
Awesome!
Thanks Fred! 馃帀馃帀
Most helpful comment
You have a few different options. If you want it to be truly global, you could use the
@!methoddirective onKernel:But you could also apply it to specific classes or modules:
The second option makes
current_uservisible in all of your controllers (i.e., any subclass ofApplicationController).Depending on your app's architecture, there might be some other module where you could apply the directive for better accuracy.