Tag Archives: ruby on rails

Why does Rails do utf8=✓

I noticed Rails apps always does utf8=✓ in their URLs. Rails at one point of time even placed a snowman unicode glyph. Here’s what Yehuda Katz has to say on this regard:

This parameter was added to forms in order to force Internet Explorer (5, 6, 7 and 8) to encode its parameters as unicode.

Specifically, this bug can be triggered if the user switches the browser’s encoding to Latin-1. To understand why a user would decide to do something seemingly so crazy, check out this google search: http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=diamond+with+a+question+mark+in+it. Once the user has put the web-site into Latin-1 mode, if they use characters that can be understood as both Latin-1 and Unicode (for instance, é or ç, common in names), Internet Explorer will encode them in Latin-1.

This means that if a user searches for “Ché Guevara”, it will come through incorrectly on the server-side. In Ruby 1.9, this will result in an encoding error when the text inevitably makes its way into the regular expression engine. In Ruby 1.8, it will result in broken results for the user.

By creating a parameter that can only be understood by IE as a unicode character, we are forcing IE to look at the accept-charset attribute, which then tells it to encode all of the characters as UTF-8, even ones that can be encoded in Latin-1.

Keep in mind that in Ruby 1.8, it is extremely trivial to get Latin-1 data into your UTF-8 database (since NOTHING in the entire stack checks that the bytes that the user sent at any point are valid UTF-8 characters). As a result, it’s extremely common for Ruby applications (and PHP applications, etc. etc.) to exhibit this user-facing bug, and therefore extremely common for users to try to change the encoding as a palliative measure.

All that said, when I wrote this patch, I didn’t realize that the name of the parameter would ever appear in a user-facing place (it does with forms that use the GET action, such as search forms). Since it does, we will rename this parameter to _e, and use a more innocuous-looking unicode character.

Very funky although this has since become my standard way of determine if the application is running on Ruby on Rails.

How to install mysql2 gem in Ubuntu

Got an error message when you install the mysql2 gem in Ubuntu? Before you install mysql2, make sure you have libmysqlclient-dev installed or you’ll get the following:

kahwee@kahwee-desktop:/$ gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
	ERROR: Failed to build gem native extension.

/home/kahwee/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/home/kahwee/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
	--with-mysql-config
	--without-mysql-config
	--with-mysql-dir
	--without-mysql-dir
	--with-mysql-include
	--without-mysql-include=${mysql-dir}/include
	--with-mysql-lib
	--without-mysql-lib=${mysql-dir}/lib
	--with-mysqlclientlib
	--without-mysqlclientlib
	--with-mlib
	--without-mlib
	--with-mysqlclientlib
	--without-mysqlclientlib
	--with-zlib
	--without-zlib
	--with-mysqlclientlib
	--without-mysqlclientlib
	--with-socketlib
	--without-socketlib
	--with-mysqlclientlib
	--without-mysqlclientlib
	--with-nsllib
	--without-nsllib
	--with-mysqlclientlib
	--without-mysqlclientlib
	--with-mygcclib
	--without-mygcclib
	--with-mysqlclientlib
	--without-mysqlclientlib


Gem files will remain installed in /home/kahwee/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6 for inspection.
Results logged to /home/kahwee/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/ext/mysql2/gem_make.out

To resolve it, install libmysqlclient-dev:

sudo apt-get install libmysqlclient-dev

And now you can install mysql2 successful:

kahwee@kahwee-desktop:/$ gem install mysql2
Building native extensions.  This could take a while...
Successfully installed mysql2-0.2.6
1 gem installed
Installing ri documentation for mysql2-0.2.6...
Installing RDoc documentation for mysql2-0.2.6...

Great!

[I tried this on Ubuntu 10.10.]

Ruby on Rails and Merb will merge

Yay. We always see opensource branch and branch. Rarely do we see them come together.

Merb is an open, ever-changing project, and some its best ideas have come from not-core regular-Joe community members. It’s gotten where it has because of the community, and the community will get us even further in the future. Your ideas, feedback and even complaints will be 100% welcome in the future, just as they have been in the past. I believe in the tremendous value an open community and just generally open attitude bring to the table, and am counting on those things to continue ushering in the future of Ruby.

On to the news: beginning today, the Merb team will be working with the Rails core team on a joint project. The plan is to merge in the things that made Merb different. This will make it possible to use Rails 3 for the same sorts of use-cases that were compelling for Merb users. Effectively, Merb 2 is Rails 3. (Source: Yehudakatz)

I don’t use Rails by the way. I use more of CakePHP. But anyway, I think the merger is a good direction. Of course this is arguable since the merger would mean one less competing Rails framework. But this is software, not business. Merger means greater understanding. I believe there are many ways of doing one same thing, but one way that would be most efficient in most given situations and that’s why people build frameworks.

Aptana acquires Pydev to add Python support

Aptana acquires Pydev. Pydev is an Eclipse plugin.

Aptana Acquires Pydev to add Python Support to Studio

We are very excited to announce that Pydev, the popular Python and Jython IDE, is now part of the Aptana product family and that Pydev creator, Fabio Zadronzy, will head up continued efforts to advance Pydev as part of the Aptana team. Like our products for Ruby on Rails, Ajax, and PHP, Pydev offers code completion, refactoring, code analysis, debugging support, and lots lots more. Pydev’s popularity in the Python community and Eclipse ecosystem made it the clear choice for Aptana. The acquisition sets the stage for a full Python suite of products and services ranging from local development to cloud deployment. (Source: Aptana)

Aptana is pretty neat. I use it for PHP and Ruby on Rails last time. But I didn’t find the syntax highlighting as good as Eclipse PDT and syntax highlighting is one of the main reasons I switched away. Pydev is pretty good already, lately they don’t have much significant updates.