Rails 升级:呈现 rxml 文件而不是 haml 文件
我正在将旧的 Rails 1.x 应用程序升级到 2.3.10,并且遇到了渲染视图的问题。我有一个控制器,它有两个与之关联的视图:index.haml
和 index.rxml
。升级之前,一切都按预期进行。迁移到 Rails 2 后,相同的代码(没有任何更改)开始在 wants.html
块的末尾自动渲染 XML 视图,而此时它应该渲染 haml 视图。当我将 index.rxml
文件重命名为其他名称(例如 foo.rxml
)时,它成功找到并呈现 index.haml
文件。
从 Rails 1 到 Rails 2 的视图渲染逻辑发生了什么变化导致了这种情况?
I'm upgrading an old Rails 1.x app to 2.3.10, and I'm running into a problem with rendering views. I have a controller that has two views associated with it: index.haml
and index.rxml
. Before the upgrade everything worked as expected. After moving to Rails 2, the same code (with no changes) has started automatically rendering the XML view at the end of the wants.html
block, when it should be rendering the haml view. When I rename the index.rxml
file to something else (like foo.rxml
), it successfully finds and renders the index.haml
file.
What changed in the view rendering logic from Rails 1 to Rails 2 that is causing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有使用过 Rails 1(开始使用 Rails 2),但我猜这是因为 Rails 2 使用 .html.erb 而不是 .rhtml。 .xml.erb 而不是 .rxml 也是如此。 HAML 也发生了同样的事情:.haml 变成了 .html.haml。不知道这是否是导致您出现问题的原因,但这是 Rails 2 创建视图的方式。
编辑
此外,如果您想在 Rails 2 中呈现 XML,您需要将以下内容添加到您的控制器中:
I haven't worked with Rails 1 (jumped in at Rails 2), but I guess it's because Rails 2 uses .html.erb instead of .rhtml. Same goes for .xml.erb instead of .rxml. And the same thing has happened for HAML: .haml becomes .html.haml. Don't know if this is the thing causing your problem, but it's the Rails 2 way of creating views.
EDIT
Also, if you want to render XML in Rails 2, you need to add the following to your Controller: