开发者

Writing out a custom file as a response from a rails controller action

So I want to dynamically generate a MIDI file on a web request.Coming from the Java world, I expected something to the tune of

class MidisController < ApplicationController
  before_filter :set_content_type    
  def set_content_type
    @headers["Content-Type"] = "audio/midi; charset=utf-8"
  end

  def show
    midi_data = get_midi_data 
    response.write(midi_data)
  end

But the API says, stay away from the response object. 开发者_高级运维Any ideas ?


Look at the Rails docs for send_file or send_data. It handles all of the header requirements for you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜