could yo开发者_如何学Pythonu tell me please - how to use method create_translation_table! of globalize2 with additional options such as :null => false, :default => "abc" ???
TRY Something like following
Post.create_translation_table! :title => :string, :text => :text, {:null=>false, :default=>"abc"}
Here is the method definition in the current version of 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
As you can see, there is no third parameter passed to the t.column
declarations. Therefore globalize2 will not support this without a patch.
My suggestion is just to manually create the migration.
精彩评论