开发者

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

开发者 https://www.devze.com 2023-01-03 08:48 出处:网络
In Ruby on Rails, http://localhost:3000/foobars/alt/1 works but http://localhost:3000/foobars/alt/1.xml

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

精彩评论

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