Running with Ruby

Tag: Rails 4 (page 3 of 7)

FriendlyId Ruby on Rails gem – update (refresh) slug after each record change

If you want to have slugs that are refreshed (updated) each time you change corresponding field in your ActiveRecord models, put this at the end of your initializers/friendly_id.rb file:

module FriendlyId
  module Slugged
    def should_generate_new_friendly_id?
      return true if send(friendly_id_config.slug_column).nil? && !send(friendly_id_config.base).nil?

      change = :"#{friendly_id_config.base}_changed?"
      return true if respond_to?(change) && send(change)

      false
    end
  end
end

This will update slug each time related column (friendly_id_config.base) has changed. Keep in mind, that this method won’t work if you use non-column slug method as a base for friendly ids, since it uses ActiveRecord::Dirty interface.

Rails 4.0.2, Resque nad Resque scheduler – 100% CPU usage

After updating resque-scheduler it started to behave really weird. The CPU would stay almost all the time around 100%. I don’t have a fix for that, but for now downgrading should be enough. You need to downgrade to following versions of those gems:

gem 'resque', '1.25.0'
gem 'resque-scheduler', '2.0.1'
gem 'rufus-scheduler', '2.0.24'
Olderposts Newerposts

Copyright © 2021 Running with Ruby

Theme by Anders NorenUp ↑