Hi there,
I've been scratching my head for the last few hours, looking for an answer but I can't find it anywhere.
My gem file:
# Use globalize for translating models
gem "globalize", github: "ncri/globalize" # for Rails 4.2
gem 'globalize-accessors', '~> 0.1.5'
# Use friendly_id for slugs
gem 'friendly_id', '~> 5.1.0'
gem 'friendly_id-globalize', '~> 1.0.0.alpha1'
Here's the situation:
- I have two languages "en" and "fr"
- 2 models : pages and pages_translations
- pages has a slug column, pages_translations also has a slug column.
- if I view the page -> en/pages/slug-en, it works.
- if I view the page -> fr/pages-slug-fr, it works.
So I assume friendly_id and globalize are properly configured.
However my problem is that I can't make a language switcher work using:
<% if I18n.locale != :en %>
<li>
<%= link_to t('menu.languages.short_en'), url_for(locale: 'en') %>
</li>
<% end %>
The route becomes en/pages/slug-fr (i.e. the language changes but not the slug).
I have activated config.use :finders in the initializer.
My page model:
translates :title, :slug, :blurb, :content, :seo_title, :seo_description, :seo_keywords
globalize_accessors :locales => [:en, :fr], :attributes => [:title, :slug, :blurb, :content, :seo_title, :seo_description, :seo_keywords]
extend FriendlyId
friendly_id :slug, :use => :globalize
validates :slug, presence: true, uniqueness: { case_sensitive: false }
So what do I need to do to have the proper path on my language switcher?
Ideally, I'd like this to work with any models, not just the Page model.
Thanks!
Hi there,
I've been scratching my head for the last few hours, looking for an answer but I can't find it anywhere.
My gem file:
Here's the situation:
So I assume friendly_id and globalize are properly configured.
However my problem is that I can't make a language switcher work using:
The route becomes en/pages/slug-fr (i.e. the language changes but not the slug).
I have activated config.use :finders in the initializer.
My page model:
So what do I need to do to have the proper path on my language switcher?
Ideally, I'd like this to work with any models, not just the Page model.
Thanks!