RailsCasts Pro episodes are now free!

Learn more or hide this

Alessandro Rodi's Profile

GitHub User: coorasse

Site: http://www.airesis.eu

Comments by Alessandro Rodi


Please note that for non-US payments payment_fee and payment_gross fields are not populated. You have to take values from mc_fee and mc_gross instead


Ryan says that actually friendly_id history doesn't work for old records but only for new ones.
That is not true anymore.
You just need to create friendly_id table before adding slug column and save your object.
Like this:

create_table :friendly_id_slugs do |t|
  t.string   :slug,           :null => false
  t.integer  :sluggable_id,   :null => false
  t.string   :sluggable_type, :limit => 40
  t.datetime :created_at
add_index :friendly_id_slugs, :sluggable_id
add_index :friendly_id_slugs, [:slug, :sluggable_type], :unique => true
add_index :friendly_id_slugs, :sluggable_type

add_column :articles, :slug, :string
add_index :articles, :slug

and everything will work fine as expected.

I also suggest, if you don't want to loose old urls, to execute this code after adding frindly_id_slugs and before adding column to articles

Article.find_each do |article|
    execute "INSERT INTO friendly_id_slugs(
            slug, sluggable_id, sluggable_type, created_at)
            VALUES ('"+"#{article.id}-#{article.name}".parameterize+"', #{article.id}, 'Article', current_timestamp);"


current_timestamp if you are using postgresql


Nice episode.
I just had to handle a situation where I had to disply a custom error message on a ActiveRecord::RecordNotFound Exception for a specific controller.
Although this episode I can't figure out how to set a custom error message.