norman/friendly_id-globalize

everything works perfect on development but not on Heroku

Closed this issue · 2 comments

gem file:

gem 'friendly_id'
gem 'globalize'
gem 'friendly_id-globalize'

globalize migration:

class AddTranslationToPost < ActiveRecord::Migration[5.1]
  def up
  	Post.create_translation_table!({
  		title: :string,
      slug: :string,
  		sub_title: :string,
  		body: :text
  		}, {migrate_data: true})
  end

  def down
  	Post.drop_translation_table!
  end
end

my model:

class Post < ApplicationRecord
  translates :title,:slug ,:sub_title ,:body
  extend FriendlyId
  friendly_id :title, use: [:globalize, :history]
  has_attached_file :image, styles: { post_index: "750x300", large: "600x600", medium: "300x300>", thumb: "100x100#{}>" }
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
 #def should_generate_new_friendly_id?
 #  title_changed?
 #end

end

show.html.erb

<%= link_to I18n.with_locale(:es){post_path(@post, locale: 'es')} do %>
  <%= image_tag('https://pilatesshopa.s3-eu-west-1.amazonaws.com/products/images/000/000/001/original/spain.png?1520005015', width: '23', height: '15.33', alt: 'English') %>
<% end %>
<%= link_to I18n.with_locale(:en){post_path(@post, locale: 'en')} do %>
  <%= image_tag('https://pilatesshopa.s3-eu-west-1.amazonaws.com/posts/images/000/000/001/original/usa.png?1520004588', width: '23', height: '15.33', alt: 'English') %>
<% end %>

friendly_id-globalize:

class AddLocaleToFriendlyIdSlugs < ActiveRecord::Migration[5.1]
  def change
    add_column :friendly_id_slugs, :locale, :string, length: 2, null: :false, after: :scope

    remove_index :friendly_id_slugs, [:slug, :sluggable_type]
    add_index :friendly_id_slugs, [:slug, :sluggable_type, :locale], length: { slug: 140, sluggable_type: 50, locale: 2 }
    remove_index :friendly_id_slugs, [:slug, :sluggable_type, :scope]
    add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope, :locale], length: { slug: 70, sluggable_type: 50, scope: 70, locale: 2 }, unique: true, name: :index_friendly_id_slugs_uniqueness
    add_index :friendly_id_slugs, :locale
  end
end

in Heroku everything is mixed up, I reset the database and it did not help.
thanks :)

update:
I added to the "gem file":

gem 'globalize-accessors'

"model"
globalize_accessors :locales => [:en, :es], :attributes => [:title]

I also had to add the links directly to the main index file and to 'post /index.html.erb' file

<%= link_to url_for(locale: :en) do %>
      <%= image_tag('https://pilatesshopa.s3-eu-west-1.amazonaws.com/posts/images/000/000/001/original/usa.png?1520004588', width: '23', height: '15.33', alt: 'English') %>
<% end %>
<%= link_to url_for(locale: :es) do %>
      <%= image_tag('https://pilatesshopa.s3-eu-west-1.amazonaws.com/products/images/000/000/001/original/spain.png?1520005015', width: '23', height: '15.33', alt: 'Spanish') %>
<% end %>

update:
i build it from scratch and it works perfect.
thank you :)