我被要求设计一个多语言应用程序,我需要有关 Rails 最佳方法的建议。
基本上所有的表都有一些不需要的公共(public)字段 需要翻译和其他一些需要翻译的内容。
谢谢
最佳答案
为此,将联系 gem globalize3 。易于使用。
在你的 gemfile 中:
gem 'globalize'
型号:
class Article < ActiveRecord::Base
translates :title, :text
end
和迁移:
class CreateArticles < ActiveRecord::Migration
def up
create_table :articles do |t|
t.timestamps
end
Article.create_translation_table! :title => :string, :text => :text
end
def down
drop_table :articles
Article.drop_translation_table!
end
end
然后运行
rake db:migrate
关于ruby-on-rails - 多种语言模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7464030/