8/09/2008

Rails on IntelliJ

As I promised I'll give my verdict on Ruby on Rails with IntelliJ. First and foremost I haven't gone back to RadRails/Aptana Studio. I've been using IntelliJ's Ruby plugin now for 2 weeks I guess, and I still really like it. It's stable and very peppy. Much more so than Java editing I hate to say, but there aren't as many features in Rails plugin as main stay Java. Just the editor alone is so much nicer than Eclipse like hitting home goes to the beginning of your code on a line not the start of the first column. And, it doesn't just crash periodically like Eclipse does. Aptana Studio was really flaky. I've only shutdown IntelliJ to reboot my machine for Apple updates so it's very stable.

By in large it covers most of rails and ruby development. You get all the comforts of home with generator scripts. Just right click on your project > New > Controller and viola it runs the Rails generator creating all of the parts you'd expect: controller, it's helper, tests, controller's view and such. You have access to all the same generators you'd expect: Controller, Model, View, Migration, plain old ruby, etc. And it works just like you expect with IntelliJ.

One draw back is undo. It looks like they tried their best to support undo'ing a generator script, but all to often it gives up saying "Undo is too complex" or something like that.

Syntax highlighting is a go. Nothing really unexpected there. Controllers, Models, Views, and even YAML editor.

Code completion. Well it doesn't work that well in Aptana, and it's not too good in IntelliJ. I've gotten to the point where I just don't use it. I think if they were to try and make this work it would have to be some sort of smart guessing going on about what you're doing. But, in the end code completion just isn't going to work for dynamic languages. Oh well.

Refactor is going to be the same verdict as Code completion. It does support move, copy, rename, and migrate. But, these aren't the fire and forgot refactorings you love with Java. Always preview...always. Sorry that's just what you have to give up when working with agile dynamic languages.

Navigating between files is just as you'd expect it with Shift-N and Ctrl-Shift-N (Splat-N and Shift Splat N for mac users). They both work well, and I go back and forth between the class version, and the file version. The class version is going to work for Controllers, Models, Tests, and Migrations. The file version will work for views, and pretty everything else. It's a little weird having these different ways you have to use, but if you're an average IntelliJ user you won't even notice. It also still carries the "Include Java Files" check box when searching in Files. That should probably be removed.

There are two views I usually go between the normal Project view, and a special Rails view. When I do Java I never switched from Project view, but the special Rails view is really quite nice. It pulls all of your code together showing your controllers, model, and tests. Under models you can access your migrations right there which is very nice. It's always a pain to navigate to the DB folder to find your migrations. It also pulls in your public folder for direct access to static resources. But, it's strangely absent of views, and this is probably why I find myself switching back to the project view. You can't see your view files (rhtml,rxml) from the Rails view. This is something I'd really wish they'd fix. It just doesn't even make sense why they left that out.

You also have access to Rake tasks as well. Just right click on your project view > Rake. From there is a bunch of fold out menus to run Rake tasks. It's really nice to see all of the options you have. I'm always finding new tasks I didn't know I got for free. The ability to view all of the Rake tasks is very important given that the Rails geeks don't document very well. But, trying to right click then navigating all of those fold out menus is a futile exercise in mouse dexterity. I'd rather see a Rake view similar to the Ant and Maven docking views. That would be really sweet. Then I can just type portions of my rake tasks and quickly run them with the find feature just like I do with Ant.

I normally use the script/server inside my own terminal to run the rails server, but IntelliJ supports running the server inside the IDE. You have all your choices of Mongrel, WEBrick, and Lighttpd. You can run your server in the various environments, but you have to specify that in the server arguments field. You can save various versions (development, production, etc) as separate programs to run, and just swap between them in the drop down box. You can run Ruby scripts, Ruby tests, Rails server, and RSpec.

The thing I miss is the ability to run the script/console from within the IDE. I think you could make IntelliJ do this as it will run normal Ruby scripts. I tried, but it failed with an exception related to readline. It probably has something to do with the fact that I rebuilt ruby to include readline library, and IntelliJ just can't load it.

I think they could make this experience a little easier by pre-populating your project with Run configurations for Developer, Test, Production, and console. That would be a nice enhancement.

Finally, the coup de grace for RadRails is that the Rails Plugin comes packed with inline template completion (remember sout?). Think TextMate like editing! The best feature of TextMate is it's fast abbreviations for common tasks in Rails. Well IntelliJ users have nothing to covet. Type vc Ctrl-J and you get a validates_confirmation_of. Type rec = redirect_to with controller. Type rf = render file. There are tons of these. Although most are targeted at Ruby, but there are some rails specifics. I'd like to see more migration templates, but the good news is you can add them.

Overall IntelliJ's rails plugin covers everything you need. I'm not switching back to Aptana/RadRails period. I think there are somethings they can improve, but overall it's the same quality you have come to love from Java development with IntelliJ. It's really one of the best Rails environments available to you.