friendly_id icon indicating copy to clipboard operation
friendly_id copied to clipboard

Rails 3.1 cached_slug column not being updated?

Open krzkrzkrz opened this issue 15 years ago • 6 comments

When creating a record that uses friendly_id, it adds the necessary records into the slugs table, but does not update the cached_slug column in the relevant table.

For example, my model looks like:

class Genre < ActiveRecord::Base
  has_friendly_id :name, :use_slug => true
  ...
end

In console, I do:

Genre.create(:name => 'Acoustic')

Slugs table is updated. The genre 'Acoustic' is created in the Genre table. But the cached_slug column in the Genre table is NULL. I am using mysql and the mysql2 gem.

This used to work with Rails 3.0.X, but not with 3.1RC. Is this a known issue? Any solutions?

krzkrzkrz avatar Jun 01 '11 11:06 krzkrzkrz

Can you send me a minimal Rails app that shows this behavior, or add a failing test case to FriendlyId? If this is indeed a bug I can solve it more quickly if I can reproduce it.

norman avatar Jun 01 '11 12:06 norman

Hmmm on further tests. It seems to work now. Strange...

krzkrzkrz avatar Jun 02 '11 04:06 krzkrzkrz

I had this problem, too, and resolved it like this spraints@156af1d54b86d945e073a53442724844e1a81e04

spraints avatar Jun 03 '11 06:06 spraints

Same problem here, @spraints could you do a pull request with your patch ?

sush avatar Jun 09 '11 14:06 sush

I can confirm that my Rails 3.1 project never updates its cached slugs with friendly_id 3.2.1. When I use spraints' fork my cached slugs work.

spikegronim avatar Jul 07 '11 21:07 spikegronim

spraints@156af1d fixes the cached_slug being empty in Rails 3.1 for me as well.

theozaurus avatar Aug 30 '11 13:08 theozaurus