在Rails 3中渲染YAML

den*_*icz 4 ruby-on-rails-3

无论如何回应.yml文件扩展名?

我试过了,但无法让它发挥作用.

respond_to do |format|
      format.xml # index.xml.builder
      format.yml {render :text => @labels.to_yaml, :content_type => 'text/yaml'}
    end
Run Code Online (Sandbox Code Playgroud)

上面的代码吐出以下错误 uninitialized constant Mime::YML

小智 5

不需要将这些东西添加到environment.rb,只需将format.yml更改为format.yaml即可.