开发者

In Ruby on Rails, why http://localhost:3000/foobars/alt/1.xml not work?

In Ruby on Rails,

http://localhost:3000/foobars/alt/1

works

but

http://localhost:3000/foobars/alt/1.xml

doesn't work.

config/route.rb is

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

so supposedly 开发者_运维问答it supports an id.format in the URL?


Ensure that your controller action has a respond to block that supports XML:

def alt
    @object = ...

    respond_to do |format|
        format.html
        format.xml { render :xml => @object.to_xml }
    end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜