我正在将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?
发布评论
评论(1)
进行了一些挖掘,但我发现这是因为模型尚未加载。
我已在这里提交了一张票(带有临时解决方法): 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