Ruby on rails 全球化与行动文本
我有一个正在使用的应用程序,我计划开始使用ActionText。所以,我有一个叫做商业的模型Ruby on rails 全球化与行动文本,ruby-on-rails,globalize,actiontext,Ruby On Rails,Globalize,Actiontext,我有一个正在使用的应用程序,我计划开始使用ActionText。所以,我有一个叫做商业的模型 class Business < ApplicationRecord translates :name, :description globalize_accessors has_rich_text :description end 它有什么问题?我如何解决这个问题 PS:我发现了,但这个解决方案看起来有点奇怪:(假设您使用globalize gem,并根据globalize d
class Business < ApplicationRecord
translates :name, :description
globalize_accessors
has_rich_text :description
end
它有什么问题?我如何解决这个问题
PS:我发现了,但这个解决方案看起来有点奇怪:(假设您使用globalize gem,并根据globalize docs进行迁移->
class CreateTranslation < ActiveRecord::Migration[6.0]
def up
Business.create_translation_table!({name: :string, description: text}, { migrate_data: true })
end
def down
Business.drop_translation_table! migrate_data: true
end
end
并尝试在视图中使用以下内容:
<%= rich_text_area_tag "business[name]", f.object.name %>
<%= rich_text_area_tag "business[description]", f.object.description %>
我就是这样解决的
class Post < ApplicationRecord
translates :title, :body, touch: true
delegate :body, to: :translation
delegate :body=, to: :translation
after_save do
body.save if body.changed?
end
class Translation
has_rich_text :body
end
class Post
我必须使用content.save if content\u change?
因为content.changed?
总是返回false。我使用content
而不是body
来避免与ActionText::RichText#body
混淆。
globalize_accessors
has_rich_text :description
<%= rich_text_area_tag "business[name]", f.object.name %>
<%= rich_text_area_tag "business[description]", f.object.description %>
class Post < ApplicationRecord
translates :title, :body, touch: true
delegate :body, to: :translation
delegate :body=, to: :translation
after_save do
body.save if body.changed?
end
class Translation
has_rich_text :body
end