为什么ActiveResource 3需要命名空间关联?

发布于 2025-01-08 12:12:09 字数 848 浏览 2 评论 0 原文

我正在将rail2应用程序升级到rails3,并在ActiveResource使用REST api(也是rails应用程序)的方式中遇到一些奇怪的行为。来自 api 的 XML 响应看起来像这样:

<company>
    <name>Company Name</name>
    <employee>
        <name>Employee 1</name>
        <position>
            <name>Manager</name>
        </position>
    </employee>
</company>

现在我能够正确使用 api,并且点表示法似乎工作正常...即:

company.employee.name #returns Employee 1

但是,我注意到嵌套属性的类类型与 Rails 中的不同2. 在 Rails 2 中,类类型(基于上面的 XML)将为:

Company
Employee
Position

但是,在 Rails 3 中,类类型为:

Company
Company::Employee
Company::Employee::Position

由于某种原因,它对类进行命名空间。我已经为每个类型(非命名空间)定义了每个 ActiveResource 类,并且因为rails3 是命名空间的东西,所以它没有映射到我定义的类。

有人知道是否有办法关闭此功能?

I'm upgrading a rail2 app to rails3, and experiencing some weird behavior with the way ActiveResource is consuming a REST api (also a rails app). The XML response from the api looks something like:

<company>
    <name>Company Name</name>
    <employee>
        <name>Employee 1</name>
        <position>
            <name>Manager</name>
        </position>
    </employee>
</company>

Now I am able to consume the api correctly, and dot notation seems to work fine...i.e.:

company.employee.name #returns Employee 1

However, I noticed that the class type of nested attributed is different than it was in rails 2. In rails two, the class types (based on the XML above), would be:

Company
Employee
Position

However, in rails 3, the class types are:

Company
Company::Employee
Company::Employee::Position

For some reason, it is namespacing the classes. I have already defined each of the ActiveResource classes for each of these types (non-namespaced), and because rails3 is namespacing things, it is not mapping to the classes I have defined.

Anyone know if there is a way to turn this off?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍景流年 2025-01-15 12:12:09

进行了一些挖掘,但我发现这是因为模型尚未加载。

我已在这里提交了一张票(带有临时解决方法): https://github.com/rails /rails/issues/5148

Took some digging around, but I discovered that this is because the models have not been loaded yet.

I've filed a ticket here (with a temporary workaround): https://github.com/rails/rails/issues/5148

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文