渲染 xml 的 Rails 路由给出 404
我面临着一个我不太明白的问题。
这是我的控制器
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在我的托管服务器中遇到了同样的问题。查看 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!