开发者

Write object to XML file (specify my own file name)

So there's the basic function like this ....

def show @position = Position.find(params[:id])

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

end

and if you go to, say, http://localhost/(position_id).xml then you will see the xml... But I wish to have a standard xml filename that I can write the object details to because I want to access it from outside rails. I am very new to rails and have not pro开发者_Python百科grammed in a while...seems like this should be easy, right ? So I just want to have a file created with a name like my_xml.xml for all the objects, rather than 1.xml, 2.xml, (id).xml, etc.

Thanks for the help !


I met similar questions, here is my solution(I am a newbie):

I added below in routes.rb:

resources do
  collection do
    get 'my_xml'
  end
end

Then added the my_xml action in controller. In my_xml action, assemble all data, and format it to xml via to_xml method.

No sure whether above is useful for you. Hope it helpful.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜