Jul
30

So, have you started to work with rails 3? Did you realize that your UTF-8 databases doesn’t work nice with mysql? This is because the mysql gem works with ASCII-8BIT encoding, but ruby 1.9 and rails 3 works with UTF-8 encoding, so when you create a model into the database, everything works fine, but when you work with those models, it doesn’t works so nice and you don’t get what you stored.
What’s the solution? Well, there are actually three solutions, the most recommended, use mysql2, in order to do this, edit your Gemfile and include:

gem "mysql2"

and then, edit your databases.yml file, and change the adapter to mysql2

development:
  adapter: mysql2
  database: fun_development
  user: root
  password:
  encoding: utf8

Another solution, is just instead of using the “mysql” gem, use the “ruby-mysql” gem, but it’s pretty slow because it’s a 100% ruby gem.

gem "ruby-mysql"

The last solution is a monkey patch, but its also slow to use it, so I really recommend using the mysql 2 gem

require 'mysql'

class Mysql::Result
  def encode(value, encoding = "utf-8")
    String === value ? value.force_encoding(encoding) : value
  end

  def each_utf8(&block)
    each_orig do |row|
      yield row.map {|col| encode(col) }
    end
  end
  alias each_orig each
  alias each each_utf8

  def each_hash_utf8(&block)
    each_hash_orig do |row|
      row.each {|k, v| row[k] = encode(v) }
      yield(row)
    end
  end
  alias each_hash_orig each_hash
  alias each_hash each_hash_utf8
end
Jul
29




I finally made my first contribution to rails, although it’s not a big fix nor anything like that, is a way to get started.


If you have read my last posts, you will see how to install and works with rails edge, but now I’ll explain how to setup a good rails environment to live in the edge and to help ruby on rails community by checking the issues posted on lighthouseapp.com to see if they are a real bug or not, to create patches for bugs, or why not, to create a new functionality for the rails framework.


Supposing that you already installed the last version of rails, you will need to get the rails code checked out from github, and make your demo project to use that version, so you can modify that version to create fixes, to test fixes, etc.

git checkout http://github.com/rails/rails.git



Now that you just create an application for doing test/development

rails new my_app



Edit the Gemfile of my_app (my_app/Gemfile) to use the rails code you are going to work with, by giving the rails gem a parameter :path where your code of ruby on rails is installed

gem 'rails', :path => File.expand_path('../../rails',  __FILE__)



And that’s all, now you can follow this guide to know how to work with git in order to post valid patches.

Jul
27

So finally, rails 3.0 RC was released, cool news because rails 3.0 brings a lot of updates and it will be very fun to develop for rails 3.0. I wonder how much work would be out there migrating rails 2.x to rails 3.x versión.
Rails 3.0 RC is out just after 21 hours bunder 1.0.0.RC.1 was released, was it really a coincidence? Yeah sure…
So how to start playing with rails 3.0.RC? Pretty easy, first, install rvm, after that, lets install ruby 1.9.2 RC 2

rvm install 1.9.2

Now let’s use ruby 1.9.2

rvm 1.9.2

Then we will install bundler, because we are using rvm, we won’t use sudo at anytime

gem install bundler -v 1.0.0.rc.1

And now we can install rails rc 1

gem install rails --pre

We can start playing with rails 3.0

rails app my_app_name
cd my_app_name
bundle install

But finally, instead of locking your development on rails 3.0.RC 1, work with the latest version of rails that is being developed (because we will find bugs in the RC), edit the Gemfile inside your application, and do these modifications

#gem 'rails', '3.0.0.rc'

# Bundle edge Rails instead:
gem 'rails', :git => 'git://github.com/rails/rails.git'

Now update your app to work with the latest version of rails

bundle install

And that’s all :)
You can report any bugs you find on https://rails.lighthouseapp.com/projects/8994-ruby-on-rails, and also check the bugs there, reproduce them and confirm that is really a bug or not, and don’t forget, you are also testing bundler 1.0.0.RC.1, so if you find any issue with bundler, you can report your issues on http://github.com/carlhuda/bundler/issues.
Remember, this is your opportunity to give something back to the open source community.

Jul
24


So you are trying to install ruby-debug to debug rails applications (or perhaps ruby-debug-ide for RubyMine) and you are having problems with it, because you have ruby 1.8.7 for your system, and you are using rvm in order to user ruby 1.9.2 to test rails edge.

The first thing to notice, is that all of the sources that you have installed with rvm are located in $rvm_path/src, so in case you are using ruby 1.9.2 rc 2 as I’m doing right now, the installation is pretty easy

gem install ruby-debug-ide19 -- --with-ruby-include=$rvm_path/src/ruby-1.9.2-rc2/

But for sure, if you are using ruby 1.9.1 or any other version, you can easily do a ls $rvm_path/src to find the right location to compile ruby-debug-ide19 into your system.

Now, you can add the gem to the Gemfile if you are planning to debug from the console

gem 'ruby-debug19', :require => 'ruby-debug', :group => :development

And then run

rails s --debug

Or if you are using rubymine, the debug will start although it’s not working yet, hopefully it will be working before rubymine 2.3.5 is released, because nobody wants to use rails3 without ruby 1.9.2, or at least I don’t want to do that :P

Jan
10


After downloading and using radiant 0.9 and globalize, I realized that I wanted to redirect the users by default with their geo location.
So I installed GeoIP and then I had to do these little modifications to the Globalize plugin.
First, I edit the file config/environment.rb and added this line, in order to load GeoIP with the application

config.gem 'geoip'

Then I updated the file vendor/extensions/globalize2/lib/globalize2/application_controller_extensions.rb

module Globalize2
  module SiteControllerExtensions
    def self.included(base)
      base.class_eval do
        alias_method_chain :find_page, :globalize

        alias_method_chain :show_page, :homepage_redir
      end
    end

    def show_page_with_homepage_redir
      url = params[:url]
      if Array === url
        url = url.join('/')
      else
        url = url.to_s
      end

      if url == '/'
        locale = params[:locale] || cookies[:locale] || session[:locale] || Globalize2Extension.ip_lookup(request.remote_ip)
        redirect_to CGI.unescape('/' + locale + '/') and return
      end

      show_page_without_homepage_redir
    end

    def find_page_with_globalize(url)
      globalized_url = '/' + I18n.locale + '/' + url
      find_page_without_globalize(globalized_url)
    end
  end
end

So, as you can see on the code, I also check if the user has the language selected in a cookie, and when the user selects (or get a locale by default), I set the cookie with the locale, so the next time the user came into the site, he will see the last language selected.
Finally, I updated the file vendor/extensions/globalize2/globalize2_extension.rb and added the following method, where I get the country code from the user, and I set the locale based on his country ip, or the default locale.

  def ip_lookup(ip)
    g = GeoIP.new( File.join(File.dirname(__FILE__), '..', '..', 'gems', 'geoip-0.8.6', 'GeoIP.dat'))
    r = g.country(ip)
    country_code = r[3]
    case country_code
      when 'DE'
        'de'
      when 'GB'
        'uk'
      when 'AU'
        'au'
      when 'FR'
        'fr'
      when ' US'
        'us'
      else
        'us'
    end
  end

And finally, we need to tell Radiant to load the GeoIP library, so in the same file, we add

  extension_config do |config|
    config.gem 'geoip', :source => 'http://github.com'
  end

So that’s all, now you have GeoIP working with globalize and Radiant 0.9 :)

Jan
09


After installing Radiant 0.9 and Globalize, I realized I had to redirect the user to their language site.


So, if the user has been assigned to the locale en, when he vist http://mysite.com he should be redirected to http://mysite.com/en


Why? Because I had some files under images with locales, and I had some flash issues that were not going to work from the homepage address.


So I ended updating the file vendor/extensions/globalize2/lib/globalize2/site_controller_extensions.rb

module Globalize2
  module SiteControllerExtensions
    def self.included(base)
      base.class_eval do
        alias_method_chain :find_page, :globalize

        alias_method :o riginal_show_page, :show_page
        alias_method :show_page, :check_homepage_redir

      end
    end

    def check_homepage_redir
      url = params[:url]
      if Array === url
        url = url.join('/')
      else
        url = url.to_s
      end

      if url == '/'
        locale = params[:locale] || cookies[:locale] || session[:locale] || Globalize2Extension.ip_lookup(request.remote_ip)
        redirect_to CGI.unescape('/' + locale + '/') and return
      end

      original_show_page
    end

    def find_page_with_globalize(url)
      globalized_url = '/' + I18n.locale + '/' + url
      find_page_without_globalize(globalized_url)
    end
  end
end
Dec
30

In the last months, I joined Vaganga, to work in what I believe, the next travel site to buy your touristic packages with an excellent price.
When I joined the company, the source code was being started by an American company called Xillent, and it was a real disaster, I don’t know where they learn to develop websites, but if you want to have a daily post in Daily WTF, be sure to hire them. So I ended rewriting a big part of the code, and luckily, we already released the first version of the web site, and although I have thought (and I’m already working) in migrating all the site to rails, while working to support the current PHP version, the site was released and it’s ready to be used.
Some points to consider to use this site for your next trip ;) :

  • It’s cheaper that many other sites, it’s one of the cheapest web sites out there.
  • Besides great prices, you can be part of the Vaganga community, with important benefits
  • We maintain an history of all your buys, an in little time, we will have discounts for people that buy on the site

For now, the site is working with VAGANGA

Dec
30


I’ve been playing with many CMS, I developed and worked on many web sites, and although Radiant 0.9 was not yet released (Radiant 0.9 RC1 was released), the updates that we have in Radiant 0.9 are great and we should strongly consider start using Radiant 0.9 right now. I don’t understand why they didn’t name it 1.0, since it’s really mature.


The actual support for multiple languages, with plugins like globalize2, save the images automatically in Amazon S3, which is pretty cheap, and you can host your site on herko for $0, and start paying once you have thousand of visits, well, I’m having dreams right now about it, but Radiant stop being a toy some time ago to be a real mature CMS and one more of the reasons that many people is migrating to Rails (because of the CMS :) ), anyway, I love playing with Radiant :P


Let’s get started. There is an excellent guide wrote by Aissac to install Radiant with Paperclip and Globalize2, but if you follow the guide step by step, you will find some troubles (I did), so I left you here a step by step guide, for beginners, so you can get your Radiant 0.9 RC 1 plus the most used plugins with support for multiple languages.


Assuming you already have installed ruby, rails, rubygem, etc. the first step is to install Radiant 0.9 RC 1, we can download it from the next address:
http://radiantcms.org/downloads/radiant-0.9.0-rc1.gem


Once you download it, execute the command:

gem install radiant-0.9.0-rc1.gem



We generate our site

radiant new_site



And we edit the database configuration file (config/database.yml)

development:
  adapter: mysql
  database: new_site_development
  username: root
  password:
  host: localhost
  encoding: utf-8



We generate the database, and we end the installation of Radiant

rake db:create
rake db:bootstrap



Now we start installing the plugins, first, copy_move plugin

git clone git://github.com/pilu/radiant-copy-move.git vendor/extensions/copy_move
rake radiant:extensions:copy_move:update
rake radiant:extensions:copy_move:migrate



We install the reorder plugin, which will allow us to order our website pages

git clone git://github.com/radiant/radiant-reorder-extension.git vendor/extensions/reorder
rake radiant:extensions:reorder:update
rake radiant:extensions:reorder:migrate



We continue with paperclip

git clone git://github.com/kbingman/paperclipped.git vendor/extensions/paperclipped
rake radiant:extensions:paperclipped:migrate
rake radiant:extensions:paperclipped:update



Now we install globalize2, which allows multiple languages on our site (even if we are just thinking about just one language)

git clone git://github.com/Aissac/radiant-globalize2-extension.git vendor/extensions/globalize2
rake radiant:extensions:globalize2:migrate
rake radiant:extensions:globalize2:update



A intermediate step before continuing, we need to edit the file config/environment.rb, and after the commented line with config.extensions, we add:

  config.extensions = [ :copy_move, :paperclipped, :globalize2, :all ]



And now, we install globalize2-paperclipped, which allow us to globalize our assets :)

git clone git://github.com/Aissac/radiant-globalize2-paperclipped-extension.git vendor/extensions/globalize2_paperclipped
rake radiant:extensions:globalize2_paperclipped:migrate
rake radiant:extensions:globalize2_paperclipped:update



The chicken is ready!!! (Argentine phrase ;) ), now you can have your site with Radiant, in multiple languages, don’t forget to check each plugin documentation, in example, to setup many languages in globalize2, edit the file config/environment.rb and add to the end of it:

Radiant::Config['globalize.default_language'] = 'sp'
Radiant::Config['globalize.languages'] = 'en,de,fr'
Dec
30


This year (2009) I’ve been pretty busy, I assisted to 14 different subjects on the university, worked on a lot of interested projects, in Ruby on Rails, PHP, and some java and C++ as well. But I’m going to get some life back to my site, in special to get new customers and show the world I’m still here :)


Today I was trying to upgrade the site to wordpress 2.9, and all the plugins I have on the site. Once I updated everything in my local machine, I got a little surprise, the qtranslate plugin is not ready to work with wordpress 2.9


However, Quian Qin is working on the plugin to make it work with the new version of wordpress, so the update will have to wait until Qian Qin ends the work on the plugin, but I’m sure there are thousands of developers out there waiting for Quian Qin work in order to upgrade their sites.


http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=3&t=1271

Dec
30


During this year, I was working as a developer in a website known as Beacon Street Girls


While working there, I first developed a cool feature by using an api provided by Doink


I think it was a great featured, and while the site was live, we got a lot of videos from the users, but a couple of months ago, because of the financial crisis, the rails site where I was working went down and now they maintain a PHP version of the site.


You can check some screens of the work done