Ruby on Rails 3.0.3中的自定义变形问题 [英] Issue with custom inflections in Ruby on Rails 3.0.3

查看:108
本文介绍了Ruby on Rails 3.0.3中的自定义变形问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 produccion_alternativa 的模型. 我在config/initializers/inflections.rb中添加了一个新的变形规则,如下所示:

I have a model called produccion_alternativa. I added a new inflection rule in config/initializers/inflections.rb, like this:

inflect.irregular('produccion_alternativa', 'producciones_alternativas')

我还有一个名为 productor 的模型,该模型与 produccion_alternativa 相关:

I have other model called productor that has a relation with produccion_alternativa:

class Productor < ActiveRecord::Base
    has_many :producciones_alternativas


class ProduccionAlternativa < ActiveRecord::Base
    belongs_to :productor

当我尝试获取生产者的所有 producciones_alternativas 时,出现此错误:

When a I try to get all the producciones_alternativas for a productor, I get this error:

irb(main):010:0> Productor.first.producciones_alternativas
NameError: uninitialized constant Productor::ProduccionesAlternativa

有什么想法吗?非常感谢

Any ideas? Thank you very much

推荐答案

我看到其他几个也有相同的问题.找不到答案的原因.因此,与此同时,您可以尝试以下操作:

I see several others having the same problem. Couldn't find an answer why this happens. So in the meantime you could just try this:

has_many :producciones_alternativas, :class_name => "ProduccionAlternativa"

这篇关于Ruby on Rails 3.0.3中的自定义变形问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆