开发者

Rails Globalize3 Get all objects regardless of locale

I have an Article model and I would like to retrieve all entries regardless of their locale.

Article.all returns only the original objects (those stored in the articles table) without their translations (translatable fields in the article_translations table). Also, objects with a different locale than the current I18n.locale have their fields set开发者_JAVA百科 to nil (?).

Article::Translation.all does return all objects regardless of language, but only from the translation class (article_translations table - which means only the fields that are set as translatable).

I'm using Rails 3.0.7 and Globalize3 0.1.0 BETA.

This is the model:

class Article < ActiveRecord::Base
  translates :title, :content, :slug, :published_at, :created_at, :updated_at
end

This is the migration file:

class CreateArticles < ActiveRecord::Migration
  def self.up
    create_table :articles do |t|
      t.string :title
      t.text :content
      t.string :slug
      t.boolean :published
      t.datetime :published_at

      t.timestamps
    end

    add_index :articles, :slug
    Article.create_translation_table! :title => :string,
                                      :content => :text,
                                      :slug => :string,
                                      :published_at => :datetime,
                                      :created_at => :datetime,
                                      :updated_at => :datetime
  end

  def self.down
    Article.drop_translation_table!
    drop_table :articles
  end
end


You have :title, :content, :slug duplicated in both tables. By your model definition, they should only be in the translation table. :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜