你能告诉我如何使用create_translation_table方法吗?使用其他选项,如:null => false、:default => "abc“?
发布于 2010-05-06 19:08:36
试试下面这样的东西:
Post.create_translation_table! :title => :string, :text => :text, {:null=>false, :default=>"abc"}发布于 2010-05-07 01:40:04
以下是当前版本globalize2中的方法定义:
def create_translation_table!(fields)
translated_attribute_names.each do |f|
raise MigrationMissingTranslatedField, "Missing translated field #{f}" unless fields[f]
end
fields.each do |name, type|
if translated_attribute_names.include?(name) && ![:string, :text].include?(type)
raise BadMigrationFieldType, "Bad field type for #{name}, should be :string or :text"
end
end
self.connection.create_table(translation_table_name) do |t|
t.references table_name.sub(/^#{table_name_prefix}/, "").singularize
t.string :locale
fields.each do |name, type|
t.column name, type
end
t.timestamps
end
self.connection.add_index(
translation_table_name,
"#{table_name.sub(/^#{table_name_prefix}/, "").singularize}_id",
:name => translation_index_name
)
end如您所见,没有第三个参数传递给t.column声明。因此,如果没有补丁,globalize2将不会支持此功能。
我的建议是手动创建迁移。
https://stackoverflow.com/questions/2780343
复制相似问题