25 November 2011

sometimes hard conventions suck (rendering partials in RoR)

I spent an hour today on this one:
partials are named with a leading underscore to distinguish them from regular views, even though they are referred to without the underscore
http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials
So I had some code that said:

  render :partial => "short_list", :collection => @items

which was in an ajax call. I was doing it with 'render :inline' but partials seemed like a much better idea. Well, that wasn't such a great idea. I kept getting ActionView::MissingTemplate errors. Tried about 15 things, read three or four blog posts, several SO questions. Then I noticed one that had an underscore in front of the file name. Odd. So I go read the docs and sure enough.

Even if you specifically say: 
  render :partial => "item/short_list", :collection => @items 
it will not find your partial because it doesn't start with an underscore. Even though there is only one view in that directory.

That, that is stupid. Conventions are fine when you want to just sorta let the app wire things up. But when you specifically say "do it this way" the convention should not get in your way. 

The odd thing about Ruby is that it is much more of an RTFM language than C# -- because there's no compiler to tell you "hey, you did that wrong" and the autocomplete is usually just not there. 

15 November 2011

More Rubymine Impressions

OK here's another couple of things I love about this IDE. For the sake of typing, RM means RubyMine.

  • Local History: you get a diff-able view of all the saves that you have made to a file. If you're using a DVCS that's 3 different views of the changes that you've made to a file. Wild. I love this because I've often thought of adding a "commit on every successful build" sort of thing to Visual Studio so that I have a step by step recreation of what I did with a file. That way if you think 'huh, that was working 20 minutes ago' you'd be able to backtrack. With RubyMine, no need. 
  • Parentheses: Seems like such a small thing, but it makes my life easier. When I type '(' into RM it gives me a closing paren for free. But if I miss that for whatever reason and then type the closing paren anyway, RM figures it out and just overwrites the closing paren that I typed. I'm waiting for this to trip me up, but it hasn't happened yet so so far it's awesome. 
  • Find is fast fast fast: So far I've got about 200 files in my app. Not many really. But when I do a Shift Ctrl F and search for a string in the files it is nearly instantaneous. It is possible that that's because the files are on an SSD. Still it seems faster than Visual Studio. 

09 November 2011

ROR + RubyMine impressions (from a .NET Dev)

Playing with RubyMine and ROR today. I'm actually hoping to build something real with this in the next few days. Well, a few days might be optimistic. I'm a .NET dev and I remember people saying that MVC was really just Microsoft-ROR. Didn't know much about it at the time but I'm starting to see it.

Here are some impressions of RubyMine and ROR, in no particular order.
  • What a deal: I got RubyMine for $35. A steal. Part of the 'Winter is coming' sale. Someone's been watching too much Game of Thrones eh? 
  • Autocompletey magic: Love the auto complete in RubyMine so far. I've never seen Visual Studio pick up on `<` as well as RubyMine does. Gives me every option that I could ever want to put next to a less than. 
  • Ruby is: I don't know yet. Still deciding. 
  • VCS: RubyMine's source control integration is effortless. Makes me wonder why MS hasn't made a decent plug in for SVN by now. If a $35 product can pull it off but a $5k+ product is 'missing' that, well what's the deal? 
  • Console: wait so I can interact with my model directly from the command line? http://guides.rubyonrails.org/getting_started.html Section 6.6 (no anchor there?!). OK that's pretty cool. 
  • Wizard-ish things: `rails generate model ...` makes Rails stronger in code generation than Visual Studio? Weird. I expected a lot of 'type this text into a new text file'. Instead there's a generator that takes care of that for me. The generator also builds functional tests and unit tests? Testing as the norm instead of a 'like-ta-have'. Huh. 
  • Associations are built into the routing (nested resource). Interesting. 
  • ASP.NET MVC = C# on Rails? Yeah I can see it. Wonder what web language used <%= %> first. 
  • Speed speed speed: this one keeps coming back to me as I read the getting started guide. Something that would take me half an hour in C# MVC would take maybe 4 mins in ROR. Most of that time is in the database. And I'm not including the migration time for a database that is in a new environment (e.g Beta) in the .NET world -- what version is the db in now and what version should it be migrated to? In C# MVC: don't know and don't know (usually). In ROR: known and known. Versioning and migration are built in over here in the ROR world. This I like. 
More later.