渲染 xml 的 Rails 路由给出 404

发布于 2024-09-29 16:20:54 字数 541 浏览 4 评论 0原文

我面临着一个我不太明白的问题。

这是我的控制器

  def index

    @resources = Resource.all(:limit => 10)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @resources }
    end
  end

当我尝试访问 html 页面时,一切正常,但是当我使用 .xml 格式时,我从日志中得到了这个讨厌的问题:

Parameters: {"name"=>[" api", "resources.xml"]}

结果导致 404 页面。 该页面是用脚手架创建的,路由规则

map.connect ':controller/:action/:id.:format'

存在,而且如果我把它放在顶部,它也不会'不工作。

我能做些什么?

I'm facing a problem I don't really understand.

This is my controller

  def index

    @resources = Resource.all(:limit => 10)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @resources }
    end
  end

When i try to access the html page, everything works fine, but when i hit the .xml format, then i got this nasty problem from the log:

Parameters: {"name"=>["api", "resources.xml"]}

Resulting in a consequential 404 page.
The page was created with a scaffold, and the routing rule

map.connect ':controller/:action/:id.:format'

exists, and also if i put it on the top, it doesn't work.

What can i do?

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

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

发布评论

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

评论(1

只涨不跌 2024-10-06 16:20:54

我在我的托管服务器中遇到了同样的问题。查看 mongrel.log 后,我意识到问题出在调度程序上。

调用 Dispatcher.dispatch 时出错 #

做了一些研究,我发现这是一个杂种错误...https://rails.lighthouseapp.com/projects/8994/tickets/4690-mongrel-doesnt-work-with-rails-238

以及解决方案中提供的相同的链接如下

创建一个 config/environment/mongrel.rb ,其中包含 以下

希望它也能帮助您!

I was having the same issue in my hosted server. After reviewing the mongrel.log I realized that the problem was with the dispatcher.

Error calling Dispatcher.dispatch #

Doing some research I found out this is a mongrel bug...https://rails.lighthouseapp.com/projects/8994/tickets/4690-mongrel-doesnt-work-with-rails-238

And the solution, provided in the same link is as follows

create a config/environment/mongrel.rb with the following

Hope it helps you as well!

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