是否可以将 globalize3 添加到外部 ActiveRecord 模型类?
我有一个项目,我使用 globalize3 gem 来允许多种语言。在我自己的模型中,我只需添加“翻译 field1、field2 等”和适当的迁移,一切都运行良好。
问题是我还有一些依赖于外部 gem 的功能。对于其中一些模型,我也想添加全球化。我没有像其他模型那样直接修改模型的代码。重新打开模型似乎不起作用。有没有一种方法可以添加将行转换为我无法直接访问的模型?
我正在使用 Rails 3.1 和 Ruby 1.9.2,以防万一。
I have a project for which I'm using the globalize3 gem to allow for multiple languages. In my own models I just add 'translates field1, field2, etc.'
and the appropriate migrations and it is all working great.
The problems is that I also have some functionality that depends on external gems. For some of those models I would like to add globalize too. I don't have the code for the models to modify directly like I did with the others. Reopening the model doesn't seem to work. Is there a way to add that translates line to models that I don't have direct access to ?
I'm using Rails 3.1 and Ruby 1.9.2 in case it matters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能提供宝石的名称和该宝石的型号吗?
类是否在模块下命名空间?如果是这样,您可能无法正确重新打开课程。我使用 qwandry gem 来检查我已包含在项目中的 gem,因此这可能会有所帮助确定这一点。当然,如果有的话,在项目网站上查看源代码也很好。
我假设当您说它不起作用时发生的情况是 I18n.locale 设置不会影响设置/获取字段,对吗?如果它正在工作但您尚未创建表,它可能会抱怨没有表。
Could you supply the name of the gem and a model from that gem?
Are the classes namespaced under a module? If so, you may not be re-opening the classes correctly. I use the qwandry gem to examine gems that I've included in my project, so that might be helpful in determining this. Of course looking at the source on the project's site is also good if it's available.
I assume that what happens when you say it isn't working is that the I18n.locale setting doesn't affect setting/getting the fields, correct? It would probably complain about there not being a table if it was working but you hadn't yet created the tables.