我希望一些用户能够下载 yaml 文件中的数据。
我看到你可以做到这一点
我跟着这个并尝试了类似的东西
定义显示
@client = Client.find(params[:id])
respond_to do |format|
format.html
format.yml { render :yml => @client.redis_to_file }
end
end
redis_to_file 返回一个带有 yaml 数据的字符串
在配置 mime_types.rb
Mime::Type.register "x-yaml", :yml
然后访问
clients/5.yml
我得到的只是“无效的模板”。 (没错,我的 View 中没有 yml 模板。)
非常感谢有关如何执行此操作以使其正常工作的任何线索。
最佳答案
试试这个:
respond_to do |format|
format.html
format.yml { send_data @client.redis_to_file, :type => 'x-yaml' }
end
Docs 中有更多选项
关于ruby-on-rails - Rails Restful 下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7682096/