我有一个Rails应用程序,我试图显示一个PNG文件,但我收到此错误:
ActionView::Template::Error (Your template was not saved as valid UTF-8. Please either specify UTF-8 as the encoding for your template in your text editor, or mark the template with its encoding by inserting the following as the first line of the template:
# encoding: <name of correct encoding>.
The source of your template was:
?PNG
IHDR#??) pHYs?]s? IDATx???g@SW?E??7?ZuV??Z?:j?m?m?Z??U[W?:??Z?*?j???@?3? I???p??}
????
???b?X?/???Z?I?N111,?O??x?T??x?mU????vtt
Run Code Online (Sandbox Code Playgroud)
我已经添加:
Mime::Type.register "image/png", :png
Run Code Online (Sandbox Code Playgroud)
到config/initializers/mime_types.rb
我在其控制器中引用并呈现png文件:
render :inline => @object.body.string, :content_type => @object.content_type || "img/png", :layout => false
Run Code Online (Sandbox Code Playgroud)
编辑: …