|
|
|
SearchCategories
|
Getting Ready for Ruby 1.9We've all been waiting for Ruby 1.9 to reach maturity for some time now. We've complained about things like Ruby's speed and weak character encoding support. We knew 1.9 could improve things, but it brings pretty big changes and a lot of Ruby 1.8 code needs updating before it can really be used there. For these and other reasons, the official production release came and went while most of us have stuck with 1.8 for our day to day needs. I think we're reaching the tipping point though. Rails runs on 1.9 now and many other libraries are beginning to become compatible. We may not yet have the full range of 1.8 goodies available on the new platform, but many of the staples are moving over and it's looking like we can now do some serious work there. Which means it's finally time for us to learn this 1.9 stuff. There are several good sources of Ruby 1.9 information now, so you have choices. I'm going to tell you about three I like. Be warned, this is a super biased list, but I really hope it will be helpful to others. My first recommendation is based on simple math: watch the Ruby 1.9 envycasts. It costs $16 and eats about an hour and fifteen minutes of your time. However, it pays you back with covering about 80% of what you need to know about Ruby 1.9. That's absurdly cheap, if you ask me. These two screencasts are quite well done. You are in the very capable hands of host David A. Black, as he guides you through syntax changes, updates to the core collection classes of Of course, nothing is perfect. I can add a few minor complaints about this series. First, David sometimes mentions syntax that has been removed without covering alternatives. For example, he mentions that At the risk of being called a traditionalist, my second recommendation is going to be the classic advice Rubyists tend to give: grab a copy of the new Pickaxe. There are some other options for a Ruby reference now and they are good. However, the Pickaxe is still the best choice, in my opinion. There's no other single source that provides an introduction to the language, all 1.9 syntax changes, details about Fibers and Oniguruma, new methods from the popular For my final suggestion, I'll go with something fun: come learn Ruby 1.9 in an all-day workshop run by Dana and myself at Lone Star Ruby Conference 2009! I ran an I/O training at last year's conference which turned out great in spite of all my first time trainer mistakes. I've used what I learned there to plan a much better session for this year. That includes bringing Dana on board as my partner, since she has years of experience doing these trainings. Pat Eyler recently interviewed us about our workshop, so check that out for more details on what we have planned. You can even stay for the rest of LSRC! Whatever path you choose, it's time to start getting up to speed on Ruby 1.9. If nothing else, install it along side your 1.8 interpreter and start trying things out in it. Start getting familiar with it and see what it's still lacking for your personal needs, if anything. The sooner we complete this transition, the better things will be for all of us. |
|
|
|
I spent a day last month getting the main Rails 2.3 app I support into shape for 1.9.
At first I was pleasantly surprised - once I'd patched a couple of gems it more or less seemed to work.
Then I tried to submit a form with UTF-8 data and got an exception. Rack was marking my input data as ASCII-8BIT and it was causing an exception when I attempted to combine it with a UTF-8 string in my controller.
Then I attempted to view a page that was pulling UTF-8 data from the MySQL database. The MySQL driver also marks all strings as ASCII-8BIT and causes the same issues.
Then I attempted to embed a UTF-8 string from my controller in an ERB template and the same thing happened, since erb is apparently encoding unaware.
Looks like there's still a few libraries to be updated before I can run my rails app on 1.9 :)
Two things:
First of all, to make it abundantly clear: Ruby 1.9 is, and has been, official for a while. To anyone reading this, if you haven’t switched… well, you should have. So go do it. Now. It’s not difficult to run Ruby 1.9 and Ruby 1.8 side–by–side for testing purposes; if you really feel the need to continue to support Ruby 1.8, you can easily do so.
Second: James, regarding encodings, I’m going to go out on a limb a little bit and suggest that the problems you describe are more user error than problems with the libraries you mentioned. I don’t use Rails or any of the things you mentioned, but it’s very much to your benefit to be explicit about encodings. If you’re storing data in your database as
'UTF–8', tell Ruby this. Don’t expect it to know it.'ASCII-8BIT'is the default in many places where Ruby thinks your data is, for whatever reason, binary—there’s quite a few tricks you can use to ensure your strings come out with the correctEncodingattached.Hi Elliott,
"If you’re storing data in your database as 'UTF–8', tell Ruby this"
With respect, can you point to the option in current versions of Rack, MySQL/Ruby or ERB that allow me to "tell Ruby" what encodings strings should be in?
If you can, I'll eat my hat.
I've never suggested the Ruby VM should magically know what encoding my strings are in. My point is just that some of the core libraries we use still need to be upgraded to be encoding aware before it's realistic for us to switch to 1.9 in production.
Same here. Tried to upgrade a production app running on Ruby 1.8.6 / Rails 2.3.2 to Ruby 1.9. I added the magic comments to my controllers and then got stuck with my views containing utf-8 characters. I found a patch on the Rails lighthouse which seems to be meant to fix the problem but I got used to Rails working out of the box and I don't want to start running production apps with a patched version of Rails.