How to get RubyMine to handle scopes correctly? - ruby-on-rails

RubyMine provides auto-completion and error/warning inspections for your code, and a lot of the time it works great, but for some reason as soon as I use a scope on one of my Rails models, all the sudden RubyMine doesn't know what the type of the result coming from the scope is.
Even simple scopes break the inspections, e.g.:
scope :all1, all()
scope :all2, all()
Is there a way to fix this? Is this a known issue in RubyMine (I'm using 5.4)?

This actually seems to be a more general problem with RubyMine being unable to identify symbols that will only be present at runtime. So, we may have to just wait for a new version of RubyMine.

Related

RubyMine code autocompletion

I'm about to get used to work with Java in Android Studio. The great thing there is that everything is strongly declared. So when I type MyClass.someme..., the IDE offers me advanced code autocompletion features. The development is rapid and pleasantly.
But then I wanted to learn RubyOnRails. I'm in love with JetBrains products and so I've installed RubyMine on my Windows machine.
Despite of a bag of problems with Windows enviroment, I was confused with not-so-well working code completion. Even if the method is known by the IDE (it can be found by Ctrl+B combination), it does not offer it in popup menu (discover the picture).
Function from railstutorial.org:
# SomeControllerHelper.rb
# Redirects to stored location (or to the default)
def redirect_back_or (default)
redirect_to(session[:forwarding_url] || default)
session.delete(:forwarding_url)
end
Is there any way to fix this problem? Are there any better IDEs with really smart code completion?
As mentioned before, Ruby's code completion is very complicated due to dynamic typing. Switching from C#/Java I've been struggling with it for some time and I've found one way to at least mitigate it a bit. Example:
def extract_data_from_this_array(input_array)
# some code
end
Suppose you want to deal with the array you're getting as an input. You type input_array and no methods or all methods are listed, because Ruby has no idea that it's an array. What I do is write:
Array.new.
And RubyMine suggests all Array methods. It helps a lot when you've just picked Ruby.
Although, RubyMine doesn't work for ALL code completion all the time due to the dynamic nature of Ruby. But, I still find it the BEST Ruby IDE for code completion, method navigation, searching features.
Here is a screenshot to show you how to configure RubyMine for Code Completion:
Here is a good tutorial by Justin Gordon which shows some awesome features of RubyMine which may interest you.
I don't know any other Ruby IDE that has smarter code completion than RubyMine. In fact, a vast majority of Ruby programmers doesn't even use an IDE, rather they use a Text Editor!
Here are couple of short sitepoint articles that would give you more insights:
Which IDEs do Rubyists Use?
What Editor Do Rubyists Use?

autocompletion not working well on NetBeans for Ruby

I'm using Netbeans 8 for Ruby development, I installed the plugins for Ruby development, from the community.
I'm working on a project, not on standalone files.
The problem that I'm facing, is: the autocomplete doesn't work all the time. Some methods don't appear in the list of autocomplete.
For instance if I type inside a class definition the beginning of a method like:
The only way to get the autocomplete working is to precede the method by it's class or object, like this:
I have also to say, that this problem occurs especially when I'm inside a class definition.
Do you have an idea, this autocompletion feature for Ruby isn't working well and how to fix it?

How to find all unused code in Ruby on Rails

I've inherited a Rails 2.3 app, which lacks a solid test suite. There is a fair amount of testing, but unfortunately, many of the tests test against old, unused models, controllers, and views.
Does anyone have a solid idea of how I might go about testing which models, controllers, views, helpers, etc. are completely unused, as well as look into the ones that ARE used and see which functions specifically are not used?
You can look at this answer, and perhaps some of the other answers listed: https://stackoverflow.com/a/9788511/485864
I would probably end up logging the methods that you have, and run your code through the paths and anything not listed in the log, may be examined to see if it is indeed not used.
RCov or SimpleCov won't do this what you want?
You can try to use RubyMine, a Rails IDE, to search for unused code. Try searching for method names and stuff like that. It's been a while since I used it so I dunno if it will have a highlight on unused methods.
Also, you can try some bash commands(grep/ack/find) to search for the code snippets.

errors when database-migration plugin is defined in BuildConfig

My attempt to follow suggested good practice and put plugins in BuildConfig.groovy instead of application.properties, won't work for database-migration. I have tried defining it with scopes of compile, build and runtime. When I run grails refresh-dependencies, I get this error message:
Error WARNING: Specified dependency definition runtime(database-migration:1.3.2) is invalid! Skipping..
(of course, the scope in the message varies with that specified). Is there another scope that I should use, or is this plugin special in some way? It's a shame that the message doesn't say what scopes are valid - that way I wouldn't have to ask this question :-)
I only want to use the plugin in the IDE to generate the xml files, and so I want to exclude it from the war file. Is that what 'export=false' indicates, if the required scope would include it by default?
I have to admit that I can't find a clear definition of the various scopes, and what scope includes what. Can anyone point me at something?
I should add that this is Grails 2.1.1, and GGTS 3.1.
I have just spotted my error. I hadn't noticed that there is a colon before the name of the plugin. I had:
runtime("database-migration:1.3.2")
what I should have written is:
runtime(":database-migration:1.3.2")
A combination of 'Duh!' and what a strange syntax that requires a colon before each term. Oh well, that's how it goes. Reminds me of a time in a customer back in dark ages, when a group of people were poring over a Cobol program that was misbehaving, and no could figure out why. I had a peep, even though I hardly knew Cobol. In a trice, I pointed out that a full-stop was missing after a 'if' statement and before the 'else'. At least a colon has two full-stops, so I may have to acknowledge that my eyesight ain't what it was...

ActiveRecord association not found - but only on second load

I recently upgraded from Rails 2.0.2 to 2.3.8 and have been ironing out the kinks. This one is baffling me.
I have a page that runs fine in production, but in development mode it runs fine on first load, then on reload it crashes with:
ActiveRecord::ConfigurationError - Association named 'average_prices' was not found; perhaps you misspelled it?
It's a nested eager-load call:
list_user.bookmarks.visible_to_user(logged_in_user_id).find(:all, :conditions=>filter, :include=>[:user, {:gift=>:average_prices}, :tags, :product_image])
My feeling is that the error isn't strictly related to the real problem... aside from the fact that the code runs correctly (in production) I have also observed other errors sporadically in my app to the effect of:
A copy of [one of my helper classes] has been removed from the module tree but is still active!
Googling for this has resulted in much discussion of marking classes as "unloaded" and using "require_dependency" instead of "require"... but I've tried a number of things without any luck.
Does anyone have any clues here? Something seems funky to me with regard to loading/reloading classes.
NOTE: I think what I'm seeing is likely the same as this, but the fix posted here didn't work for me.
I've had similar problems when I was using certain plugins. Could this come from a plugin?

Resources