SEO-friendly Rails? friendly_id FTW!

By Patrick Hawley on December 4, 2010

Having come to the Rails party while it was already underway, I've never quite understood the whole motivation for (or tolerance of) a URL such as:

  http://www.foo.com/bars/24

I don't really care to advertise the id, nor am I wanting Google to tell those who search for the number 24 that I'm the bomb.

In the past, I've used the ol' to_param:

def to_param
  "#{id}-#{title}"
end

and keeping the id in to ensure uniqueness, but...um...ids? 24? (see above)

So colour me gobsmacked that Norman Clarke has written a wonderful little gem called friendly_id!

"Great," you say to me dripping with sarcasm, "but how muckety-muck must I do with routes, controllers, models, existing links, fella?"

The answer is "Um, none?", possibly with an additional "...and please don't call me fella."

It Just Kinda Works™!

It uses babosa's multi-language slugification, which is nice. Actually, to be more accurate babosa was pulled out of friendly_id so that others may use the babosa library on its own.

So keep your ids to yourself, use friendly_id, buy Norman Clarke the odd bottle of Chipotle Tabasco Sauce for his efforts, go forth and rock some SEO-Friendly Rails!

Upgrade Magento from 1.1 to 1.4

By Aaron Hinni on November 22, 2010

Recently we had a client who needed their Magento 1.1 installation upgraded to the latest greatest 1.4. What we thought should be a nice simple task turned into one really long weekend and then some.

Upgrading the database

The initial attempts of using whatever the recommended procedure is proved to fail. Google searches all said the same thing. It broke.

The approach we took ended up being somewhat simple. All done on a development environment.

  1. Create a separate magento_upgrade database
  2. Dump the production database and import it into magento_upgrade
  3. Download and extract magento 1.2, 1.3, and 1.4
  4. Fix some PHP errors in 1.2 and 1.3
  5. Run the 1.2 and 1.3 install scripts from the command line
  6. Go through the 1.4 install
  7. Rejoice

1. Create a separate magento_upgrade database

In all of the below examples, we'll assume a local mysql database with username root and an empty password.

create database magento_upgrade;

2. Dump the production database and import it into magento_upgrade

Your parameters may vary.

> mysqldump -uroot magento magento_old > old_1.1.sql
> mysql -uroot -Dmagento_upgrade < old_1.1.sql

3. Download and extract magento 1.2, 1.3, and 1.4

Go to Magento Downloads and click on the "Release Archives" tab. Under the 1.3 group, just grab the latest 1.3 and the latest 1.2. I've read after the fact that you may just be able to use 1.3. Your mileage may vary.

4. Fix some PHP errors in 1.2 and 1.3

You need PHP 5.x for the newer Magento. Unfortunately there are some backwards compatibility issues with the older PHP that need to be resolved with magento-1.2 and magento-1.3.

First, in lib/Varien/Object.php, change:

public function ___toString(array $arrAttributes = array(), 
                            $valueSeparator=',')

to this:

 public function __invoke(array $arrAttributes = array(), 
                          $valueSeparator=',')

Then bust out your favorite text editor and change all occurrences of split to explode.

5. Run the 1.2 and 1.3 install scripts from the command line

Each tree has an install.php that you can look at for command line reference. For me it went a little something like this:

php -f install.php -- --license_agreement_accepted yes
   --encryption_key 90210ff2a6bd4217blahblahblah
   --url "http://localhost/magento" --use_rewrites yes 
   --locale en_US --timezone "America/Chicago" 
   --default_currency USD --db_host localhost
   --db_name magento_upgrade --db_user root -
   -db_pass '' --admin_lastname Hinni 
   --admin_firstname Aaron --admin_email aaron@vedadev.com 
   --admin_username admin --admin_password anadminpassword 
   --use_secure no --secure_base_url parameter '' 
   --use_secure_admin ''

6. Go through the 1.4 install

Once everything works, point your browser to wherever you installed 1.4 and point it to your new database. Hopefully all is well!

7. Rejoice

Well, not quite, as there is the matter of upgrading your theme...

Theme Upgrade

No magic advice here. After just going through this, I highly recommend just starting from scratch creating a new theme/skin based off of base. Good luck!

If you are converting a theme, one of the gotcha's I ran into involved some of the forms not saving. It ended up the form was just missing a hidden form_key field. Add this in the form block:

<?php echo $this->getBlockHtml('formkey')?>

We used our newly developed Ruby on Rails based CMS for their site and blog, and utilized the infrastructure and bandwidth already provided by Once Films's Vimeo account to allow them to easily display their portfolio on their site and in their blog.

Once-ssOnce Films

Recent tweet:

Back to using my good friends Ruby, Mechanize and Nokogiri today. Great tools when a RESTful web service is unavailable. – @aaronhinni

Technologies we Rock:

Besides Ruby on Rails, we are well versed with other goodies like Javascript, PHP, Perl, Ruby without the Rails, C/C++, Objective C, Smalltalk, Erlang, and the list goes on and on.

Follow us on facebook Veda's Facebook Page