首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails 3渲染问题

Rails 3渲染问题
EN

Stack Overflow用户
提问于 2010-12-21 01:09:49
回答 1查看 767关注 0票数 0

我正在编写一个脚本,允许用户通过URL参数传递格式。我可以根据需要使用JSON和XML,但不能使用YAML。

代码语言:javascript
复制
case params[:format]
        when "xml" then respond_with(@labels)
        when "json" then respond_with(@labels_hash.to_json)
        when "yaml" then render :text => @labels_hash.to_yaml
      end

由于某些原因,当我在URL中传递format=yaml时,我的脚本试图强制下载一个文件。为什么会发生这种情况呢?

工作代码:

代码语言:javascript
复制
case params[:format]
        when "xml" then respond_with(@labels)
        when "json" then respond_with(@labels_hash.to_json)
        when "yaml" then respond_with(@labels_hash) do |format|
          format.yaml { render :text => @labels_hash.to_s }
        end
      end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-12-21 02:19:00

尝试:

:yaml添加到控制器中的respond_to :yaml,并且:

代码语言:javascript
复制
respond_to do |format|
  ....other formats....
  format.yaml { render :yaml => @labels_hash }
end
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4492011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档