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?
Related
I'm building a ruby on rails application with most of the views with react. I'm considering using CodeMirror as an editor for users to type in code. I want them to be able to submit the code, and the code will be run through some of my test cases and get results back, similar to how codecademy works.
What are some initial steps to achieve this?
Thank you!
Have a look at the http://reactrb.org site. There is live code editors on there. Source code for the doc site is on github.
If the code examples are in either ruby or JS you can run the test scripts in the browser (for ruby you will use opal-rspec) This makes sandboxing easy.
Sounds like a great project. If you need additional questions or help stop in at https://gitter.im/zetachang/react.rb There are a couple of people there who can help you out with the details.
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.
The Less gem has been superseded by less.js, which runs on the server with Node.js. More, the "official" Less plugin for Rails, hasn't been updated since June 14, 2010.
In light of all that, what is the recommended way to use Less with Rails these days? I suppose I could always just use client-side JS for this, which everyone seems to be embracing. But I'm not crazy about relying on client-side JS just to transform a stylesheet, especially considering that I'd like to degrade gracefully. I realize that Less.js is considered very fast, but as a matter of principle, I don't want my CSS to be utterly dependent on the browser's JS engine.
Assuming I want to compile Less server-side, what is the best practice these days for use with Rails? I know you can run Less using Node.js, but I'm looking for nice Rails integration such as we once had with More.
I'm looking for something that will work on Linux and Mac. Ideally, it would be a gem or a Rails plugin, not a standalone app.
Update: I'm looking into whether The Ruby Racer can be used to embed Less.js into a Rails app. Does anyone have opinions on that?
Update 2: This question is really old, but for anyone who's still interested, I just wanted to point out that Rails 3 comes with SCSS integration out of the box. SCSS is a LESS competitor, and I'm quite happy with it.
Try out less.app for Mac OSX. http://incident57.com/less/
Use it on your local dev to generate the CSS.
My only complaint is that the parsing sometimes gets tripped up on IE specific CSS rules that are invalid CSS but were handled fine by the more gem.
Also it doesn't handle the less partials (_file.less) that more does.
Bryan here, developer of Less.app
You can handle ANY IE-specific code in Less just by using the escape function, which takes a string. Thus, you could write: e("filter:alpha..."); in your LESS file and it will compile to the expected IE-specific (though non-standard) CSS.
See Lesscss.org for more info. The bit about the e() function is all the way at the bottom of the docs.
May be not helpful at all, but the approach we currently use (PHP/node dev) is client-side .less during development, and delivering compiled .css on deploy, using lessc. That can be integrated into build scripts or commit hooks, no bundled magic :)
I'm one of those developers who isn't using TextMate with any of his Ruby/Ruby on Rails work. My particular loyalty in this arena lies with vim. What are your favorite tips/tricks for using vim with Ruby and/or Ruby on Rails to make you as efficient as possible when working?
Most important
Get a copy of rails.vim it is awesome on millions of levels. Read the doc. There are way too many tips, :Rview customer, :RSmodel foo, :Rinvert, gf, :Rextract, :Rake and the list goes on and on. You will probably want NERDTree as well for easy navigation (which you can access using :Rtree)
Second most important
Follow tpope on twitter (the author of fugative, rails.vim, haml.vim, vividchalk theme, cucumber.vim and so on), he seems to be posting new related to Rails vim plugins quite regularly (be it syntax highlighting or git integration).
You might want to checkout my ruby/rails specific vimfiles.
Its a useful starting point and has many useful Ruby/Rails plugins bundled and configured.
The one thing that really sucks about Textmate is that it doesn't run on Linux. My vim/gvim config is the same on Mac, Windows and Linux. Same fonts, same themes, same plugins and same customizations.
I mostly use Textmate for snippets and quick evaluations for posting here.
I wrote an in depth guide on using Textmate features (especially Rails related features) in VIM. It's very relevant to this question.
http://www.jackkinsella.ie/2011/09/05/textmate-to-vim.html
I don't use vim, instead, I'm like those millions of developers using Textmate. Nevertheless, a colleague does use vim/gvim.
By looking at him work, one of the things I wish I could do in Textmate is the ease of working on multiple files at the same time. Basically, you can easily manipulate multiple windows, which is quite handy.
I'm running Rails 2.2.2. I've read a few articles about ruby-prof and profiling a rails app. And I'm confused as to how things are really working.
I was originally using this tutorial
http://snippets.aktagon.com/snippets/255-How-to-profile-your-Rails-and-Ruby-applications-with-ruby-prof
to profile my app, and it works. This involves writing your own profile environment and running > RAILS_ENV=profiling ./script/performance/request -n 100 profiling/homepage.rb
So here's my confusion. Somehow, this runs ruby-prof and opens up all the stats etc, but I can't see anywhere where ruby-prof is ever actually called.
So then I read further, and it seems 2.2.2 has benchmarking/profiling built in. So I write a test file in the performance section like so
require 'test_helper'
require 'performance_test_help'
# Profiling results for each test method are written to tmp/performance.
class BrowsingTest < ActionController::PerformanceTest
def test_worksheet
get '/reduction/worksheet'
end
end
and run
rake test:profile
Is this equivalent to what I was doing above, but just now it's integrated into the whole rails framework?
My next question is this. The original script ouput a flat file and html file, but I couldn't figure out how to also get a tree file automatically to open up with KCacheGrind, or in my case MacCallGrind. Can I add formats into my script call?
Edit: running the scripts through rake test seem to actually produce a tree file, great. Mac CallGrind however seems to hang when trying to parse it. Anyone know other tools for viewing these tree files?
Turns out, it's exactly the same, I must have been reading an old tutorial. All the benchmarking and profiling is now in Rails which is awesome. And it outputs txt,html and tree files, also awesome. Now if Only MacCallGrind would work, there's no way I'm installing the 4gb of KDE packages needed just to view a tree file.
Brad, you should contact the author of MacCallGrind and see if there's an update, or whether he/she has a fix for your files.
Oh that's right, that's me. Please email at richard at symbol aggmedia.net, as there is an update about to come out, and I'd love to have Ruby/Rails support available.