I am building a Rails application using ActiveAdmin, Globalize and FriendlyId.
In my model I settled up the Globalize and FriendlyId parameters (extract):
class Post < ActiveRecord::Base
translates :title, :slug, :content
active_admin_translates :title, :slug, :content do
validates :title, presence: true
end
extend FriendlyId
friendly_id :slug_candidates,
use: [:slugged, :history, :globalize, :finders]
private
def slug_candidates
[[:title, :deduced_id]]
end
# Used to add prefix number if slug already exists
def deduced_id
count = Post.where(title: title).count
return count + 1 unless count == 0
end
end
However, when I update an article title in ActiveAdmin, the slug is never updated by friendly_id, so I added this method:
def should_generate_new_friendly_id?
title_changed? || super
end
When I do that, title_changed? is always false as new title is not sent to the model for a reason I don’t know but for other parameters not translated they are getted properly.
Ex:
logger.debug(title) # => Give me new updated title value BUT
title_changed? # => Always nil
online_changed? # => Works
How is it possible that the model doesn’t know about the update of translated attributes ?
What did I miss ?
Thanks for your help !
My Project:
- Rails 4.2.7.1 / Ruby 2.3.0
- ActiveAdmin 1.0.0pre4
- Globalize 5.0.1
- FriendlyId 5.1.0
- FriendlyId Globalize 1.0.0.alpha2
Edit: (Extract of my form)
f.translated_inputs 'Translated fields', switch_locale: true do |t|
t.input :title
t.input :content
end